1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/nsFormControlFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,179 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsFormControlFrame.h" 1.10 +#include "nsGkAtoms.h" 1.11 +#include "nsLayoutUtils.h" 1.12 +#include "nsIDOMHTMLInputElement.h" 1.13 +#include "mozilla/EventStateManager.h" 1.14 +#include "mozilla/LookAndFeel.h" 1.15 +#include "nsDeviceContext.h" 1.16 + 1.17 +using namespace mozilla; 1.18 + 1.19 +//#define FCF_NOISY 1.20 + 1.21 +nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) : 1.22 + nsLeafFrame(aContext) 1.23 +{ 1.24 +} 1.25 + 1.26 +nsFormControlFrame::~nsFormControlFrame() 1.27 +{ 1.28 +} 1.29 + 1.30 +nsIAtom* 1.31 +nsFormControlFrame::GetType() const 1.32 +{ 1.33 + return nsGkAtoms::formControlFrame; 1.34 +} 1.35 + 1.36 +void 1.37 +nsFormControlFrame::DestroyFrom(nsIFrame* aDestructRoot) 1.38 +{ 1.39 + // Unregister the access key registered in reflow 1.40 + nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false); 1.41 + nsLeafFrame::DestroyFrom(aDestructRoot); 1.42 +} 1.43 + 1.44 +NS_QUERYFRAME_HEAD(nsFormControlFrame) 1.45 + NS_QUERYFRAME_ENTRY(nsIFormControlFrame) 1.46 +NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame) 1.47 + 1.48 +NS_IMPL_FRAMEARENA_HELPERS(nsFormControlFrame) 1.49 + 1.50 +nscoord 1.51 +nsFormControlFrame::GetIntrinsicWidth() 1.52 +{ 1.53 + // Provide a reasonable default for sites that use an "auto" height. 1.54 + // Note that if you change this, you should change the values in forms.css 1.55 + // as well. This is the 13px default width minus the 2px default border. 1.56 + return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2); 1.57 +} 1.58 + 1.59 +nscoord 1.60 +nsFormControlFrame::GetIntrinsicHeight() 1.61 +{ 1.62 + // Provide a reasonable default for sites that use an "auto" height. 1.63 + // Note that if you change this, you should change the values in forms.css 1.64 + // as well. This is the 13px default width minus the 2px default border. 1.65 + return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2); 1.66 +} 1.67 + 1.68 +nscoord 1.69 +nsFormControlFrame::GetBaseline() const 1.70 +{ 1.71 + NS_ASSERTION(!NS_SUBTREE_DIRTY(this), 1.72 + "frame must not be dirty"); 1.73 + // Treat radio buttons and checkboxes as having an intrinsic baseline 1.74 + // at the bottom of the control (use the bottom content edge rather 1.75 + // than the bottom margin edge). 1.76 + return mRect.height - GetUsedBorderAndPadding().bottom; 1.77 +} 1.78 + 1.79 +nsresult 1.80 +nsFormControlFrame::Reflow(nsPresContext* aPresContext, 1.81 + nsHTMLReflowMetrics& aDesiredSize, 1.82 + const nsHTMLReflowState& aReflowState, 1.83 + nsReflowStatus& aStatus) 1.84 +{ 1.85 + DO_GLOBAL_REFLOW_COUNT("nsFormControlFrame"); 1.86 + DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); 1.87 + 1.88 + if (mState & NS_FRAME_FIRST_REFLOW) { 1.89 + RegUnRegAccessKey(static_cast<nsIFrame*>(this), true); 1.90 + } 1.91 + 1.92 + nsresult rv = nsLeafFrame::Reflow(aPresContext, aDesiredSize, aReflowState, 1.93 + aStatus); 1.94 + if (NS_FAILED(rv)) { 1.95 + return rv; 1.96 + } 1.97 + 1.98 + if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) { 1.99 + float inflation = nsLayoutUtils::FontSizeInflationFor(this); 1.100 + aDesiredSize.Width() *= inflation; 1.101 + aDesiredSize.Height() *= inflation; 1.102 + aDesiredSize.UnionOverflowAreasWithDesiredBounds(); 1.103 + FinishAndStoreOverflow(&aDesiredSize); 1.104 + } 1.105 + return NS_OK; 1.106 +} 1.107 + 1.108 +nsresult 1.109 +nsFormControlFrame::RegUnRegAccessKey(nsIFrame * aFrame, bool aDoReg) 1.110 +{ 1.111 + NS_ENSURE_ARG_POINTER(aFrame); 1.112 + 1.113 + nsPresContext* presContext = aFrame->PresContext(); 1.114 + 1.115 + NS_ASSERTION(presContext, "aPresContext is NULL in RegUnRegAccessKey!"); 1.116 + 1.117 + nsAutoString accessKey; 1.118 + 1.119 + nsIContent* content = aFrame->GetContent(); 1.120 + content->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey); 1.121 + if (!accessKey.IsEmpty()) { 1.122 + EventStateManager* stateManager = presContext->EventStateManager(); 1.123 + if (aDoReg) { 1.124 + stateManager->RegisterAccessKey(content, (uint32_t)accessKey.First()); 1.125 + } else { 1.126 + stateManager->UnregisterAccessKey(content, (uint32_t)accessKey.First()); 1.127 + } 1.128 + return NS_OK; 1.129 + } 1.130 + return NS_ERROR_FAILURE; 1.131 +} 1.132 + 1.133 +void 1.134 +nsFormControlFrame::SetFocus(bool aOn, bool aRepaint) 1.135 +{ 1.136 +} 1.137 + 1.138 +nsresult 1.139 +nsFormControlFrame::HandleEvent(nsPresContext* aPresContext, 1.140 + WidgetGUIEvent* aEvent, 1.141 + nsEventStatus* aEventStatus) 1.142 +{ 1.143 + // Check for user-input:none style 1.144 + const nsStyleUserInterface* uiStyle = StyleUserInterface(); 1.145 + if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || 1.146 + uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) 1.147 + return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); 1.148 + 1.149 + return NS_OK; 1.150 +} 1.151 + 1.152 +void 1.153 +nsFormControlFrame::GetCurrentCheckState(bool *aState) 1.154 +{ 1.155 + nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(mContent); 1.156 + if (inputElement) { 1.157 + inputElement->GetChecked(aState); 1.158 + } 1.159 +} 1.160 + 1.161 +nsresult 1.162 +nsFormControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue) 1.163 +{ 1.164 + return NS_OK; 1.165 +} 1.166 + 1.167 +// static 1.168 +nsRect 1.169 +nsFormControlFrame::GetUsableScreenRect(nsPresContext* aPresContext) 1.170 +{ 1.171 + nsRect screen; 1.172 + 1.173 + nsDeviceContext *context = aPresContext->DeviceContext(); 1.174 + int32_t dropdownCanOverlapOSBar = 1.175 + LookAndFeel::GetInt(LookAndFeel::eIntID_MenusCanOverlapOSBar, 0); 1.176 + if ( dropdownCanOverlapOSBar ) 1.177 + context->GetRect(screen); 1.178 + else 1.179 + context->GetClientRect(screen); 1.180 + 1.181 + return screen; 1.182 +}