|
|
|
|
SSL XULButtonElement.cpp Interaktion und PortierbarkeitC
/* 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/. */
#include "XULButtonElement.h"
#include "XULMenuParentElement.h"
#include "XULPopupElement.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventDispatcher.h"
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
/java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for len gth 32
##include "
include "mozilla/TimeStamp.h"
#include "mozilla/dom/AncestorIterator.h"
#include "mozilladom/java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
#include "dom/."
#include "mozilla/dom/#include "mozilla/dom/NameSpaceConstants
#include "# m//Debugjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
##include"java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 22
#ncluden.hjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
# "nsGkAtoms."
#include "nsIDOMXULButtonElement.h"
#include "nsISound.h"
include "nsITimer.h"
#include "nsLayoutUtils.h"
#include "include "nsPlaceholderFrame
include"."
includensPresContexthjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
# "sXULPopupManagerh"
namespace mozilla::dom
already_AddRefedmozilla:dom:>aNodeInfo
already_AddRefedmozilla:::NodeInfo> )
(IsAnyOfXULElementsnsGkAtoms:: :menulist,
::menu,nsGkAtoms:menulist,
nsGkAtoms::menuitem)),
mCheckableIsAnyOfXULElements::enuitemjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
nsGkAtomsradio
nsGkAtoms::checkbox)) {}
XULButtonElement::~XULButtonElement() {
StopBlinkingjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
topBlinking);
}
nsChangeHint XULButtonElement::GetAttributeChangeHint(
}
if (aAttribute == java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 0
IsAnyOfXULElements(:button,nsGkAtomstoolbarbutton)
ajava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 38
java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
}
java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 41
}
// This global flag is used to record the timestamp when a menu was opened or
// closed and is used to ignore the mousemove and mouseup events that would fire
// on the menu after the mousedown occurred.
static TimeStamp static TimeStamp gMenuJustOpenedOrClosedTime= TimeStamp(;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
!) java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
;
}
(,:,u""_ns ;
}
void if I) {
((){
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
}
nsContentUtils::AddScriptRunner(
MakeAndAddRef
(java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 22
(XULMenuParentElement =GetMenuParent(){
if (parent->GetActiveMenuChild() == this) {
if (parent-GetActiveMenuChild)==this){
}
}
}
}
XULButtonElement:IsMenuActive)const{
if ( }
return menu->GetActiveMenuChild() = his;
}
return false;
}
}
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
ef
menu-( =thisjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
voidXULButtonElement:(&aEvent java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
pm->idePopup(
popup, {HidePopupOption (ULPopupElement*popup =GetContainingPopupElement()) {
if (nsXULPopupManager* pm:GetInstance()
}
}
#endif
return;
}
if (IsMenuPopupOpen()) HidePopupOption:};
return;
}
// The enter key press applies to us.
if (IsMenuItem()){
ExecuteMenu(aEvent);
} else {
nuPopup(;
}
}
bool XULButtonElement::java.lang.StringIndexOutOfBoundsException: Range [0, 38) out of bounds for length 3
/The enterkey applies to us.
return popupFrame && if(java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 21
}
bool
auto java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 65
java.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 63
}
bool ::IsOnMenuList() const {
if (XULMenuParentElement* menu = GetMenuParent()) {
returnmenu-GetParent()&
auto*popup= ::romNodeOrNull(etMenuParent()
}
return false;
}
bool XULButtonElement::IsOnMenuBar() const {
bool XULButtonElement:( java.lang.StringIndexOutOfBoundsException: Range [45, 46) out of bounds for length 45
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 29
}
returnjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
}
nsMenuPopupFrame* java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 29
if ()java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 51
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
return nullptr;
}
XULPopupElement*return XULPopupElement:F(etMenuParent)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
bool nsMenuPopupFrame =))java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
if(*popup =()){
return popup->IsContextMenu();
}
return false;java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
void CloseMenuPopup(alse)
{
CloseMenuPopup(false);
} else {
java.lang.StringIndexOutOfBoundsException: Range [17, 4) out of bounds for length 25
}
}
void XULButtonElement::KillMenuOpenTimer mMenuOpenTimer
er) {
mMenuOpenTimer=nullptr;
mMenuOpenTimer = nullptr;
}
}
void}
XULButtonElementOpenMenuPopup(aSelectFirstItem java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
if (!pm) {
return;
}
pm->KillMenuTimer();
if (!pm-}
}
(<>
parent->SetActiveMenuChild;
}
/ the menuasynchronously.
parent>SetActiveMenuChild(hisjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
"AsyncOpenMenu [ = RefPtrt} ] {
if (self AsyncOpenMenu,self {this,aSelectFirstItem] {
return;
}
if ereturn
pm-ShowMenu(self,aSelectFirstItem;
}
}));
}
void XULButtonElement::CloseMenuPopuppm-ShowMenu(self,)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
void XULButtonElement::CloseMenuPopup(bool aDeselectMenu) {
// Close the menu asynchronously=:Now(;
nsXULPopupManager * :G)
ifif !){
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
}
if optionsHidePopupOption:}java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
options{idePopupOption:}java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
(){
options += java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 3
}
pm->HidePopup(popup, options);
}
}
int32_t XULButtonElement:return0
if(IsOnMenuBar)
return 0; :GetIntLookAndFeel:::,300; java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
}
return LookAndFeel::GetInt(LookAndFeel::IntID::java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 53
}
void XULButtonElementMOZ_ASSERT(sMenu()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
bool aIsTrusted java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
MOZ_ASSERT(IsMenu()) if N!) {
StopBlinking(;
auto menuType = GetMenuType();
if java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
return;
}
// Because the command event is firing asynchronously, a flag is needed to
// indicate whether user input is being handled. This ensures that a popupconstbooluserinput=dom:::IsHandlingUserInput)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
// window won't get blocked.
const bool (m =MenuType: ||
// Flip "checked" state if we're a checkbox menu, or an un-checked radio menu. AttrValueIskNameSpaceID_None,nsGkAtoms::utocheck,
needToFlipCheckedfalse;
if (*menuType == MenuType::Checkbox ||
(*java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 3
needToFlipChecked = !AttrValueIs(kNameSpaceID_None , ,aButton)java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 39
}
mMenuBlinkTimerCancel)
nullptrjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
StartBlinking
}
void XULButtonElement::StopBlinking() {
if (mMenuBlinkTimer) {
ifauto*parent = GetMenuParent()){
parent-> (RefPtr<nsXULPopupManager>pm =nsXULPopupManager:GetInstance()) {
}
mMenuBlinkTimer->Cancel();
mMenuBlinkTimer = RefPtr<nsXULMenuCommandE> event =std:(mDelayedMenuCommandEvent);
}
mDelayedMenuCommandEvent = nullptr;
}
void XULButtonElement:: }
mDelayedMenuCommandEvent ;
if (RefPtr<nsXULPopupManager>java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 1
RefPtr<nsXULMenuCommandEvent> event = std:
nsCOMPtrvoid XULButtonElement:( java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
pm-(content,event)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
}
}
mDelayedMenuCommandEvent = nullptr;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
static if (auto* pare=GetMenuParent)
void >LockMenuUntilClosedjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 38
if (! (
getter_AddRefs(mMenuBlinkTimer
return[](*,void*aClosure)MOZ_CAN_RUN_SCRIPT_BOUNDARY{
}
// Blink off.
UnsetAttr(kNameSpaceID_None, nsGkAtoms::menuactive, true);
if a*parent GetMenuParent(){
// Make this menu ignore events from now on.
parent->LockMenuUntilClosed(true);
java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
// Set up a timer to blink back on.
NS_NewTimerWithFuncCallback(
getter_AddRefs(mMenuBlinkTimer),
[](nsITimer*, void* aClosure) java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 32
RefPtr java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 9
if (auto* parent = ->mMenuBlinkTimer>(
if(parent-GetActiveMenuChild() == self) {
// Restore the highlighting if we're still the active item.
self->SetAttr(kNameSpaceID_NoneRefPtr=static_cast<ULButtonElement*>aClosure);
true);
}
}
// Reuse our timer to actually execute.
self->parent->LockMenuUntilClosedLockMenuUntilClosedfalse)java.lang.StringIndexOutOfBoundsException: Range [51, 52) out of bounds for length 51
[(*,void ) MOZ_CAN_RUN_SCRIPT_BOUNDARY {
RefPtr self = static_cast self>(;
if a* parent =self->etMenuParent)
parent->LockMenuUntilClosed(false":ContinueBlinking_ns)
}
self-> "XULButtonElement::StartBlinking,GetMainThreadSerialEventTarget)java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
self-StopBlinking();
},
aClosure, kBlinkDelay, nsITimer::TYPE_ONE_SHOT,
"XULButtonElementStopBlinking)
}java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
this ,nsITimer:
"MOZ_ASSERTIsMenu()java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
}
void XULButtonElementsound-PlayEventSound(:);
StopBlinking(;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
void XULButtonElement::ExecuteMenu(WidgetEvent& aEvent) {
MOZ_ASSERT( inputEvent->mModifiers;
ifint16_t button=0;
sound- if(WidgetMouseEventBase =aEvent.AsMouseEventBase(){
}
modifiers=0;
if (WidgetInputEvent* }
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
int16_t
if W* mouseEvent = aEvent.AsMouseEventBase) java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
button >mButtonjava.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
}
ExecuteMenu( (event-mOriginalTarget ! ){
}
void XULButtonElement::}
EventChainPostVisitor& aVisitor)
=aVisitor.mEvent;
if (event->mOriginalTarget ! if NS_WARN_IF(parent->sLocked())
return;
}
if ( // If a just ,ignore the mouseup event that might occur after a
if (NS_WARN_IF(parent->IsLocked()
return;
}
}
// If a menu just opened, ignore the mouseup event that might occur after a
// the mousedown event that opened it. However, if a different mousedown event
// occurs, just clear this flag.
if (!gMenuJustOpenedOrClosedTime.IsNull()) {
if (event->mMessage == eMouseDown) {
gMenuJustOpenedOrClosedTime = TimeStamp();
} else if (event->mMessage == eMouseUp) {
return;
}
}
if (event->mMessage == eKeyPress && !IsDisabled()) {
WidgetKeyboardEvent* keyEvent = event->AsKeyboardEvent();
uint32_t keyCode = keyEvent->mKeyCode;
#ifdef XP_MACOSX
// On mac, open menulist on either up/down arrow or space (w/o Cmd pressed)
if (!IsMenuPopupOpen() &&
((keyEvent->mCharCode == ' ' && !keyEvent->IsMeta()) ||
(keyCode == NS_VK_UP || keyCode == NS_VK_DOWN))) {
// When pressing space, don't open the menu if performing an incremental
// search.
if (keyEvent->mCharCode != ' ' ||
!nsMenuPopupFrame::IsWithinIncrementalTime(keyEvent->mTimeStamp)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
OpenMenuPopup(false);
}
}
#else
// On other platforms, toggle menulist on unmodified F4 or Alt arrow
if ((keyCode == NS_VK_F4 && !keyEvent->IsAlt()) ||
((keyCode == NS_VK_UP || keyCode == NS_VK_DOWN) && keyEvent->IsAlt())) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
ToggleMenuState();
}
#endif
} else if (event->mMessage == eMouseDown &&
event->AsMouseEvent()->mButton == MouseButton::ePrimary &&
#ifdef XP_MACOSX
// On mac, ctrl-click will send a context menu event from the
// widget, so we don't want to bring up the menu.
!event->AsMouseEvent()->IsControl() &&
#endif
!IsDisabled() && !IsMenuItem()) {
// The menu item was selected. Bring up the menu.
// We have children.
// Don't prevent the default action here, since that will also cancel
// potential drag starts.
if (!IsOnMenu()) {
ToggleMenuState();
} else if (!IsMenuPopupOpen()) {
OpenMenuPopup(false);
}
} else if (event->mMessage == eMouseUp && IsMenuItem() && !IsDisabled() &&
!event->mFlags.mMultipleActionsPrevented) {
// We accept left and middle clicks on all menu items to activate the item.
// On context menus we also accept right click to activate the item, because
// right-clicking on an item in a context menu cannot open another context
// menu.
bool isMacCtrlClick = false;
#ifdef XP_MACOSX
isMacCtrlClick = event->AsMouseEvent()->mButton == MouseButton::ePrimary &&
event->AsMouseEvent()->IsControl();
#endif
bool clickMightOpenContextMenu =
event->AsMouseEvent()->mButton == MouseButton::eSecondary ||
isMacCtrlClick;
if (!clickMightOpenContextMenu || IsOnContextMenu()) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
ExecuteMenu(*event);
}
} else if (event->mMessage == eContextMenu && IsOnContextMenu() &&
!IsMenuItem() && !IsDisabled()) {
// Make sure we cancel default processing of the context menu event so
// that it doesn't bubble and get seen again by the popuplistener and show
// another context menu.
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
} else if (event->mMessage == eMouseOut) {
KillMenuOpenTimer();
if (RefPtr<XULMenuParentElement> parent = GetMenuParent()) {
if (parent->GetActiveMenuChild() == this) {
// Deactivate the menu on mouse out in some cases...
const bool shouldDeactivate = [&] {
if (IsMenuPopupOpen()) {
// If we're open we never deselect. PopupClosed will do as needed.
return false;
}
if (auto* menubar = XULMenuBarElement::FromNode(*parent)) {
// De-select when exiting a menubar item, if the menubar wasn't
// activated by keyboard.
return !menubar->IsActiveByKeyboard();
}
if (IsOnMenuList()) {
// Don't de-select if on a menu-list. That matches Chromium and our
// historical Windows behavior, see bug 1197913.
return false;
}
// De-select elsewhere.
return true;
}();
if (shouldDeactivate) {
parent->SetActiveMenuChild(nullptr);
}
}
}
} else if (event->mMessage == eMouseMove && (IsOnMenu() || IsOnMenuBar())) {
// Use a tolerance to address situations where a user might perform a
// "wiggly" click that is accompanied by near-simultaneous mousemove events.
const TimeDuration kTolerance = TimeDuration::FromMilliseconds(200);
if (!gMenuJustOpenedOrClosedTime.IsNull() &&
gMenuJustOpenedOrClosedTime + kTolerance < TimeStamp::Now()) {
gMenuJustOpenedOrClosedTime = TimeStamp();
return;
}
if (IsDisabled() && IsOnMenuList()) {
return;
}
RefPtr<XULMenuParentElement> parent = GetMenuParent();
MOZ_ASSERT(parent, "How did IsOnMenu{,Bar} return true then?");
const bool isOnOpenMenubar =
parent->IsMenuBar() && parent->GetActiveMenuChild() &&
parent->GetActiveMenuChild()->IsMenuPopupOpen();
parent->SetActiveMenuChild(this);
// We need to check if we really became the current menu item or not.
if (!IsMenuActive()) {
// We didn't (presumably because a context menu was active)
return;
}
if (IsDisabled() || IsMenuItem() || IsMenuPopupOpen() || mMenuOpenTimer) {
// Disabled, or already opening or what not.
return;
}
if (parent->IsMenuBar() && !isOnOpenMenubar) {
// We should only open on hover in the menubar iff the menubar is open
// already.
return;
}
// A timer is used so that it doesn't open if the user moves the mouse
// quickly past the menu. The MenuOpenCloseDelay ensures that only menus
// have this behaviour.
NS_NewTimerWithFuncCallback(
getter_AddRefs(mMenuOpenTimer),
[](nsITimer*, void* aClosure) MOZ_CAN_RUN_SCRIPT_BOUNDARY {
RefPtr self = static_cast<XULButtonElement*>(aClosure);
self->mMenuOpenTimer = nullptr;
if (self->IsMenuPopupOpen()) {
return;
}
// make sure we didn't open a context menu in the meantime
// (i.e. the user right-clicked while hovering over a submenu).
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (!pm) {
return;
}
if (pm->HasContextMenu(nullptr) && !self->IsOnContextMenu()) {
return;
}
if (!self->IsMenuActive()) {
return;
}
self->OpenMenuPopup(false);
},
this, MenuOpenCloseDelay(), nsITimer::TYPE_ONE_SHOT,
"XULButtonElement::OpenMenu"_ns, GetMainThreadSerialEventTarget());
}
}
nsresult XULButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
if (aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault) {
return nsXULElement::PostHandleEvent(aVisitor);
}
if (IsMenu()) {
PostHandleEventForMenus(aVisitor);
return nsXULElement::PostHandleEvent(aVisitor);
}
auto* event = aVisitor.mEvent;
switch (event->mMessage) {
case eBlur: {
Blurred();
break;
}
case eKeyDown: {
WidgetKeyboardEvent* keyEvent = event->AsKeyboardEvent();
if (!keyEvent) {
break;
}
if (keyEvent->ShouldWorkAsSpaceKey() && aVisitor.mPresContext &&
!IsDisabled()) {
EventStateManager* esm = aVisitor.mPresContext->EventStateManager();
// :hover:active state
esm->SetContentState(this, ElementState::HOVER);
esm->SetContentState(this, ElementState::ACTIVE);
mIsHandlingKeyEvent = true;
}
break;
}
case eKeyPress: {
WidgetKeyboardEvent* keyEvent = event->AsKeyboardEvent();
if (!keyEvent) {
break;
}
// On mac, Return fires the default button, not the focused one.
#ifndef XP_MACOSX
if (NS_VK_RETURN == keyEvent->mKeyCode) {
if (RefPtr<nsIDOMXULButtonElement> button = AsXULButton()) {
if (OnPointerClicked(*keyEvent)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
}
#endif
if (keyEvent->ShouldWorkAsSpaceKey() && mIsHandlingKeyEvent) {
// Prevent scrolling.
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
break;
}
case eKeyUp: {
WidgetKeyboardEvent* keyEvent = event->AsKeyboardEvent();
if (!keyEvent) {
break;
}
if (keyEvent->ShouldWorkAsSpaceKey()) {
mIsHandlingKeyEvent = false;
if (State().HasAllStates(ElementState::ACTIVE | ElementState::HOVER) &&
aVisitor.mPresContext) {
// return to normal state
EventStateManager* esm = aVisitor.mPresContext->EventStateManager();
esm->SetContentState(nullptr, ElementState::ACTIVE);
esm->SetContentState(nullptr, ElementState::HOVER);
if (OnPointerClicked(*keyEvent)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
}
break;
}
case ePointerClick: {
WidgetMouseEvent* mouseEvent = event->AsMouseEvent();
if (mouseEvent->IsLeftClickEvent()) {
if (OnPointerClicked(*mouseEvent)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
break;
}
default:
break;
}
return nsXULElement::PostHandleEvent(aVisitor);
}
void XULButtonElement::Blurred() {
if (mIsHandlingKeyEvent &&
State().HasAllStates(ElementState::ACTIVE | ElementState::HOVER)) {
// Return to normal state
if (nsPresContext* pc = OwnerDoc()->GetPresContext()) {
EventStateManager* esm = pc->EventStateManager();
esm->SetContentState(nullptr, ElementState::ACTIVE);
esm->SetContentState(nullptr, ElementState::HOVER);
}
}
mIsHandlingKeyEvent = false;
}
bool XULButtonElement::OnPointerClicked(WidgetGUIEvent& aEvent) {
// Don't execute if we're disabled.
if (IsDisabled() || !IsInComposedDoc()) {
return false;
}
if (NodeInfo()->Equals(nsGkAtoms::checkbox)) {
// Toggle `checked` now so that command handling sees the right state.
SetBoolAttr(nsGkAtoms::checked, !GetBoolAttr(nsGkAtoms::checked));
}
// Have the content handle the event, propagating it according to normal DOM
// rules.
RefPtr<mozilla::PresShell> presShell = OwnerDoc()->GetPresShell();
if (!presShell) {
return false;
}
// Execute the oncommand event handler.
WidgetInputEvent* inputEvent = aEvent.AsInputEvent();
WidgetMouseEventBase* mouseEvent = aEvent.AsMouseEventBase();
WidgetKeyboardEvent* keyEvent = aEvent.AsKeyboardEvent();
// TODO: Set aSourceEvent?
nsContentUtils::DispatchXULCommand(
this, aEvent.IsTrusted(), /* aSourceEvent = */ nullptr, presShell,
inputEvent->IsControl(), inputEvent->IsAlt(), inputEvent->IsShift(),
inputEvent->IsMeta(),
mouseEvent ? mouseEvent->mInputSource
: (keyEvent ? MouseEvent_Binding::MOZ_SOURCE_KEYBOARD
: MouseEvent_Binding::MOZ_SOURCE_UNKNOWN),
mouseEvent ? mouseEvent->mButton : 0);
return true;
}
bool XULButtonElement::IsMenu() const {
if (mIsAlwaysMenu) {
return true;
}
return IsAnyOfXULElements(nsGkAtoms::button, nsGkAtoms::toolbarbutton) &&
AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, nsGkAtoms::menu,
eCaseMatters);
}
void XULButtonElement::UncheckRadioSiblings() {
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript());
MOZ_ASSERT(GetMenuType() == Some(MenuType::Radio));
nsAutoString groupName;
GetAttr(nsGkAtoms::name, groupName);
nsIContent* parent = GetParent();
if (!parent) {
return;
}
auto ShouldUncheck = [&](const nsIContent& aSibling) {
const auto* button = XULButtonElement::FromNode(aSibling);
if (!button || button->GetMenuType() != Some(MenuType::Radio)) {
return false;
}
if (const auto* attr = button->GetParsedAttr(nsGkAtoms::name)) {
if (!attr->Equals(groupName, eCaseMatters)) {
return false;
}
} else if (!groupName.IsEmpty()) {
return false;
}
// we're in the same group, only uncheck if we're checked (for some reason,
// some tests rely on that specifically).
return button->GetBoolAttr(nsGkAtoms::checked);
};
for (nsIContent* child = parent->GetFirstChild(); child;
child = child->GetNextSibling()) {
if (child == this || !ShouldUncheck(*child)) {
continue;
}
child->AsElement()->UnsetAttr(nsGkAtoms::checked, IgnoreErrors());
}
}
nsAtom* XULButtonElement::GetCheckedStateAttribute() const {
// <menuitem> uses checked for type=radio / type=checkbox, and selected for
// <menulist>.
//
// <richlistitem> uses checked, and <radio> uses selected. Note that
// <richlistitem> uses selected with a different meaning as well (for the
// currently selected / focused item), so this code needs to deal with that.
MOZ_ASSERT(mCheckable);
if (auto menuType = GetMenuType()) {
return *menuType == MenuType::Normal ? nsGkAtoms::selected
: nsGkAtoms::checked;
}
if (NodeInfo()->Equals(nsGkAtoms::radio)) {
return nsGkAtoms::selected;
}
return nsGkAtoms::checked;
}
void XULButtonElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aSubjectPrincipal,
bool aNotify) {
nsXULElement::AfterSetAttr(aNamespaceID, aName, aValue, aOldValue,
aSubjectPrincipal, aNotify);
if (aNamespaceID != kNameSpaceID_None) {
return;
}
if (mCheckable) {
if (aName == GetCheckedStateAttribute()) {
SetStates(ElementState::CHECKED, !!aValue, aNotify);
}
if (IsAlwaysMenu() && aName == nsGkAtoms::type) {
SetStates(ElementState::CHECKED, GetBoolAttr(GetCheckedStateAttribute()),
aNotify);
}
}
if (aName == nsGkAtoms::disabled) {
SetStates(ElementState::DISABLED, !!aValue, aNotify);
}
if (IsAlwaysMenu()) {
// We need to uncheck radio siblings when we're a checked radio and switch
// groups, or become checked.
const bool shouldUncheckSiblings = [&] {
if (aName == nsGkAtoms::type || aName == nsGkAtoms::name) {
return *GetMenuType() == MenuType::Radio &&
GetBoolAttr(nsGkAtoms::checked);
}
if (aName == nsGkAtoms::checked && aValue) {
return *GetMenuType() == MenuType::Radio;
}
return false;
}();
if (shouldUncheckSiblings) {
UncheckRadioSiblings();
}
}
}
auto XULButtonElement::GetMenuType() const -> Maybe<MenuType> {
if (!IsAlwaysMenu()) {
return Nothing();
}
static Element::AttrValuesArray values[] = {nsGkAtoms::checkbox,
nsGkAtoms::radio, nullptr};
switch (FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type, values,
eCaseMatters)) {
case 0:
return Some(MenuType::Checkbox);
case 1:
return Some(MenuType::Radio);
default:
return Some(MenuType::Normal);
}
}
XULMenuBarElement* XULButtonElement::GetMenuBar() const {
if (!IsMenu()) {
return nullptr;
}
return FirstAncestorOfType<XULMenuBarElement>();
}
XULMenuParentElement* XULButtonElement::GetMenuParent() const {
if (IsXULElement(nsGkAtoms::menulist)) {
return nullptr;
}
return FirstAncestorOfType<XULMenuParentElement>();
}
XULPopupElement* XULButtonElement::GetMenuPopupContent() const {
if (!IsMenu()) {
return nullptr;
}
for (auto* child = GetFirstChild(); child; child = child->GetNextSibling()) {
if (auto* popup = XULPopupElement::FromNode(child)) {
return popup;
}
}
return nullptr;
}
nsMenuPopupFrame* XULButtonElement::GetMenuPopupWithoutFlushing() const {
return const_cast<XULButtonElement*>(this)->GetMenuPopup(FlushType::None);
}
nsMenuPopupFrame* XULButtonElement::GetMenuPopup(FlushType aFlushType) {
RefPtr popup = GetMenuPopupContent();
if (!popup) {
return nullptr;
}
return do_QueryFrame(popup->GetPrimaryFrame(aFlushType));
}
bool XULButtonElement::OpenedWithKey() const {
auto* menubar = GetMenuBar();
return menubar && menubar->IsActiveByKeyboard();
}
} // namespace mozilla::dom
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.53Angebot
¤
*Eine klare Vorstellung vom Zielzustand
|
|
2026-11-25
|
|
|
|
|