/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsresult nsNumberControlFrame::CreateAnonymousContent(
nsTArray<ContentInfo>& aElements) { // We create an anonymous tree for our input element that is structured as // follows: // // input // div - placeholder // div - preview div // div - editor root // div - spin box wrapping up/down arrow buttons // div - spin up (up arrow button) // div - spin down (down arrow button) // // If you change this, be careful to change the order of stuff returned in // AppendAnonymousContentTo.
#ifdefined(MOZ_WIDGET_ANDROID) // We don't want spin buttons on Android return NS_OK; #else // The author has elected to hide the spinner by setting this // -moz-appearance. We will reframe if it changes. if (StyleDisplay()->EffectiveAppearance() == StyleAppearance::Textfield) { return NS_OK;
}
// Create the ::-moz-number-spin-box pseudo-element:
mButton = MakeAnonElement(PseudoStyleType::mozNumberSpinBox);
// Create the ::-moz-number-spin-up pseudo-element:
mSpinUp = MakeAnonElement(PseudoStyleType::mozNumberSpinUp, mButton);
// Create the ::-moz-number-spin-down pseudo-element:
mSpinDown = MakeAnonElement(PseudoStyleType::mozNumberSpinDown, mButton);
aElements.AppendElement(mButton);
return NS_OK; #endif
}
/* static */
nsNumberControlFrame* nsNumberControlFrame::GetNumberControlFrameForSpinButton(
nsIFrame* aFrame) { // If aFrame is a spin button for an <input type=number> then we expect the // frame of the NAC root parent to be that input's frame. We have to check for // this via the content tree because we don't know whether extra frames will // be wrapped around any of the elements between aFrame and the // nsNumberControlFrame that we're looking for (e.g. flex wrappers).
nsIContent* content = aFrame->GetContent(); auto* nacHost = content->GetClosestNativeAnonymousSubtreeRootParentOrHost(); if (!nacHost) { return nullptr;
} auto* input = HTMLInputElement::FromNode(nacHost); if (!input || input->ControlType() != FormControlType::InputNumber) { return nullptr;
} return do_QueryFrame(input->GetPrimaryFrame());
}
if (!mButton) { // we don't have a spinner return eSpinButtonNone;
} if (aEvent->mOriginalTarget == mSpinUp) { return eSpinButtonUp;
} if (aEvent->mOriginalTarget == mSpinDown) { return eSpinButtonDown;
} if (aEvent->mOriginalTarget == mButton) { // In the case that the up/down buttons are hidden (display:none) we use // just the spin box element, spinning up if the pointer is over the top // half of the element, or down if it's over the bottom half. This is // important to handle since this is the state things are in for the // default UA style sheet. See the comment in forms.css for why.
LayoutDeviceIntPoint absPoint = aEvent->mRefPoint;
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, absPoint, RelativeTo{mButton->GetPrimaryFrame()}); if (point != nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) { if (point.y < mButton->GetPrimaryFrame()->GetSize().height / 2) { return eSpinButtonUp;
} return eSpinButtonDown;
}
} return eSpinButtonNone;
}
void nsNumberControlFrame::SpinnerStateChanged() const { if (mSpinUp) {
nsIFrame* spinUpFrame = mSpinUp->GetPrimaryFrame(); if (spinUpFrame && spinUpFrame->IsThemed()) {
spinUpFrame->InvalidateFrame();
}
} if (mSpinDown) {
nsIFrame* spinDownFrame = mSpinDown->GetPrimaryFrame(); if (spinDownFrame && spinDownFrame->IsThemed()) {
spinDownFrame->InvalidateFrame();
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.