layout/forms/nsFormControlFrame.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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsFormControlFrame.h"
     7 #include "nsGkAtoms.h"
     8 #include "nsLayoutUtils.h"
     9 #include "nsIDOMHTMLInputElement.h"
    10 #include "mozilla/EventStateManager.h"
    11 #include "mozilla/LookAndFeel.h"
    12 #include "nsDeviceContext.h"
    14 using namespace mozilla;
    16 //#define FCF_NOISY
    18 nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
    19   nsLeafFrame(aContext)
    20 {
    21 }
    23 nsFormControlFrame::~nsFormControlFrame()
    24 {
    25 }
    27 nsIAtom*
    28 nsFormControlFrame::GetType() const
    29 {
    30   return nsGkAtoms::formControlFrame; 
    31 }
    33 void
    34 nsFormControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
    35 {
    36   // Unregister the access key registered in reflow
    37   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
    38   nsLeafFrame::DestroyFrom(aDestructRoot);
    39 }
    41 NS_QUERYFRAME_HEAD(nsFormControlFrame)
    42   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
    43 NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
    45 NS_IMPL_FRAMEARENA_HELPERS(nsFormControlFrame)
    47 nscoord
    48 nsFormControlFrame::GetIntrinsicWidth()
    49 {
    50   // Provide a reasonable default for sites that use an "auto" height.
    51   // Note that if you change this, you should change the values in forms.css
    52   // as well.  This is the 13px default width minus the 2px default border.
    53   return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
    54 }
    56 nscoord
    57 nsFormControlFrame::GetIntrinsicHeight()
    58 {
    59   // Provide a reasonable default for sites that use an "auto" height.
    60   // Note that if you change this, you should change the values in forms.css
    61   // as well. This is the 13px default width minus the 2px default border.
    62   return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
    63 }
    65 nscoord
    66 nsFormControlFrame::GetBaseline() const
    67 {
    68   NS_ASSERTION(!NS_SUBTREE_DIRTY(this),
    69                "frame must not be dirty");
    70   // Treat radio buttons and checkboxes as having an intrinsic baseline
    71   // at the bottom of the control (use the bottom content edge rather
    72   // than the bottom margin edge).
    73   return mRect.height - GetUsedBorderAndPadding().bottom;
    74 }
    76 nsresult
    77 nsFormControlFrame::Reflow(nsPresContext*          aPresContext,
    78                            nsHTMLReflowMetrics&     aDesiredSize,
    79                            const nsHTMLReflowState& aReflowState,
    80                            nsReflowStatus&          aStatus)
    81 {
    82   DO_GLOBAL_REFLOW_COUNT("nsFormControlFrame");
    83   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
    85   if (mState & NS_FRAME_FIRST_REFLOW) {
    86     RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
    87   }
    89   nsresult rv = nsLeafFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
    90                                     aStatus);
    91   if (NS_FAILED(rv)) {
    92     return rv;
    93   }
    95   if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
    96     float inflation = nsLayoutUtils::FontSizeInflationFor(this);
    97     aDesiredSize.Width() *= inflation;
    98     aDesiredSize.Height() *= inflation;
    99     aDesiredSize.UnionOverflowAreasWithDesiredBounds();
   100     FinishAndStoreOverflow(&aDesiredSize);
   101   }
   102   return NS_OK;
   103 }
   105 nsresult
   106 nsFormControlFrame::RegUnRegAccessKey(nsIFrame * aFrame, bool aDoReg)
   107 {
   108   NS_ENSURE_ARG_POINTER(aFrame);
   110   nsPresContext* presContext = aFrame->PresContext();
   112   NS_ASSERTION(presContext, "aPresContext is NULL in RegUnRegAccessKey!");
   114   nsAutoString accessKey;
   116   nsIContent* content = aFrame->GetContent();
   117   content->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
   118   if (!accessKey.IsEmpty()) {
   119     EventStateManager* stateManager = presContext->EventStateManager();
   120     if (aDoReg) {
   121       stateManager->RegisterAccessKey(content, (uint32_t)accessKey.First());
   122     } else {
   123       stateManager->UnregisterAccessKey(content, (uint32_t)accessKey.First());
   124     }
   125     return NS_OK;
   126   }
   127   return NS_ERROR_FAILURE;
   128 }
   130 void 
   131 nsFormControlFrame::SetFocus(bool aOn, bool aRepaint)
   132 {
   133 }
   135 nsresult
   136 nsFormControlFrame::HandleEvent(nsPresContext* aPresContext, 
   137                                 WidgetGUIEvent* aEvent,
   138                                 nsEventStatus* aEventStatus)
   139 {
   140   // Check for user-input:none style
   141   const nsStyleUserInterface* uiStyle = StyleUserInterface();
   142   if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
   143       uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
   144     return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
   146   return NS_OK;
   147 }
   149 void
   150 nsFormControlFrame::GetCurrentCheckState(bool *aState)
   151 {
   152   nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(mContent);
   153   if (inputElement) {
   154     inputElement->GetChecked(aState);
   155   }
   156 }
   158 nsresult
   159 nsFormControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
   160 {
   161   return NS_OK;
   162 }
   164 // static
   165 nsRect
   166 nsFormControlFrame::GetUsableScreenRect(nsPresContext* aPresContext)
   167 {
   168   nsRect screen;
   170   nsDeviceContext *context = aPresContext->DeviceContext();
   171   int32_t dropdownCanOverlapOSBar =
   172     LookAndFeel::GetInt(LookAndFeel::eIntID_MenusCanOverlapOSBar, 0);
   173   if ( dropdownCanOverlapOSBar )
   174     context->GetRect(screen);
   175   else
   176     context->GetClientRect(screen);
   178   return screen;
   179 }

mercurial