layout/forms/nsGfxCheckboxControlFrame.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsGfxCheckboxControlFrame.h"
michael@0 7 #include "nsIContent.h"
michael@0 8 #include "nsCOMPtr.h"
michael@0 9 #include "nsRenderingContext.h"
michael@0 10 #include "nsIDOMHTMLInputElement.h"
michael@0 11 #include "nsDisplayList.h"
michael@0 12 #include <algorithm>
michael@0 13
michael@0 14 using namespace mozilla;
michael@0 15
michael@0 16 static void
michael@0 17 PaintCheckMark(nsIFrame* aFrame,
michael@0 18 nsRenderingContext* aCtx,
michael@0 19 const nsRect& aDirtyRect,
michael@0 20 nsPoint aPt)
michael@0 21 {
michael@0 22 nsRect rect(aPt, aFrame->GetSize());
michael@0 23 rect.Deflate(aFrame->GetUsedBorderAndPadding());
michael@0 24
michael@0 25 // Points come from the coordinates on a 7X7 unit box centered at 0,0
michael@0 26 const int32_t checkPolygonX[] = { -3, -1, 3, 3, -1, -3 };
michael@0 27 const int32_t checkPolygonY[] = { -1, 1, -3, -1, 3, 1 };
michael@0 28 const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(int32_t);
michael@0 29 const int32_t checkSize = 9; // 2 units of padding on either side
michael@0 30 // of the 7x7 unit checkmark
michael@0 31
michael@0 32 // Scale the checkmark based on the smallest dimension
michael@0 33 nscoord paintScale = std::min(rect.width, rect.height) / checkSize;
michael@0 34 nsPoint paintCenter(rect.x + rect.width / 2,
michael@0 35 rect.y + rect.height / 2);
michael@0 36
michael@0 37 nsPoint paintPolygon[checkNumPoints];
michael@0 38 // Convert checkmark for screen rendering
michael@0 39 for (int32_t polyIndex = 0; polyIndex < checkNumPoints; polyIndex++) {
michael@0 40 paintPolygon[polyIndex] = paintCenter +
michael@0 41 nsPoint(checkPolygonX[polyIndex] * paintScale,
michael@0 42 checkPolygonY[polyIndex] * paintScale);
michael@0 43 }
michael@0 44
michael@0 45 aCtx->SetColor(aFrame->StyleColor()->mColor);
michael@0 46 aCtx->FillPolygon(paintPolygon, checkNumPoints);
michael@0 47 }
michael@0 48
michael@0 49 static void
michael@0 50 PaintIndeterminateMark(nsIFrame* aFrame,
michael@0 51 nsRenderingContext* aCtx,
michael@0 52 const nsRect& aDirtyRect,
michael@0 53 nsPoint aPt)
michael@0 54 {
michael@0 55 nsRect rect(aPt, aFrame->GetSize());
michael@0 56 rect.Deflate(aFrame->GetUsedBorderAndPadding());
michael@0 57
michael@0 58 rect.y += (rect.height - rect.height/4) / 2;
michael@0 59 rect.height /= 4;
michael@0 60
michael@0 61 aCtx->SetColor(aFrame->StyleColor()->mColor);
michael@0 62 aCtx->FillRect(rect);
michael@0 63 }
michael@0 64
michael@0 65 //------------------------------------------------------------
michael@0 66 nsIFrame*
michael@0 67 NS_NewGfxCheckboxControlFrame(nsIPresShell* aPresShell,
michael@0 68 nsStyleContext* aContext)
michael@0 69 {
michael@0 70 return new (aPresShell) nsGfxCheckboxControlFrame(aContext);
michael@0 71 }
michael@0 72
michael@0 73 NS_IMPL_FRAMEARENA_HELPERS(nsGfxCheckboxControlFrame)
michael@0 74
michael@0 75
michael@0 76 //------------------------------------------------------------
michael@0 77 // Initialize GFX-rendered state
michael@0 78 nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame(nsStyleContext* aContext)
michael@0 79 : nsFormControlFrame(aContext)
michael@0 80 {
michael@0 81 }
michael@0 82
michael@0 83 nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
michael@0 84 {
michael@0 85 }
michael@0 86
michael@0 87 #ifdef ACCESSIBILITY
michael@0 88 a11y::AccType
michael@0 89 nsGfxCheckboxControlFrame::AccessibleType()
michael@0 90 {
michael@0 91 return a11y::eHTMLCheckboxType;
michael@0 92 }
michael@0 93 #endif
michael@0 94
michael@0 95 //------------------------------------------------------------
michael@0 96 void
michael@0 97 nsGfxCheckboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 98 const nsRect& aDirtyRect,
michael@0 99 const nsDisplayListSet& aLists)
michael@0 100 {
michael@0 101 nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
michael@0 102
michael@0 103 // Get current checked state through content model.
michael@0 104 if ((!IsChecked() && !IsIndeterminate()) || !IsVisibleForPainting(aBuilder))
michael@0 105 return; // we're not checked or not visible, nothing to paint.
michael@0 106
michael@0 107 if (IsThemed())
michael@0 108 return; // No need to paint the checkmark. The theme will do it.
michael@0 109
michael@0 110 aLists.Content()->AppendNewToTop(new (aBuilder)
michael@0 111 nsDisplayGeneric(aBuilder, this,
michael@0 112 IsIndeterminate()
michael@0 113 ? PaintIndeterminateMark : PaintCheckMark,
michael@0 114 "CheckedCheckbox",
michael@0 115 nsDisplayItem::TYPE_CHECKED_CHECKBOX));
michael@0 116 }
michael@0 117
michael@0 118 //------------------------------------------------------------
michael@0 119 bool
michael@0 120 nsGfxCheckboxControlFrame::IsChecked()
michael@0 121 {
michael@0 122 nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
michael@0 123 bool retval = false;
michael@0 124 elem->GetChecked(&retval);
michael@0 125 return retval;
michael@0 126 }
michael@0 127
michael@0 128 bool
michael@0 129 nsGfxCheckboxControlFrame::IsIndeterminate()
michael@0 130 {
michael@0 131 nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
michael@0 132 bool retval = false;
michael@0 133 elem->GetIndeterminate(&retval);
michael@0 134 return retval;
michael@0 135 }

mercurial