layout/forms/nsFormControlFrame.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial