Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 "nsCOMPtr.h" |
michael@0 | 7 | #include "nsPresContext.h" |
michael@0 | 8 | #include "nsGkAtoms.h" |
michael@0 | 9 | #include "nsButtonBoxFrame.h" |
michael@0 | 10 | #include "nsITimer.h" |
michael@0 | 11 | #include "nsRepeatService.h" |
michael@0 | 12 | #include "mozilla/MouseEvents.h" |
michael@0 | 13 | #include "nsIContent.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla; |
michael@0 | 16 | |
michael@0 | 17 | class nsAutoRepeatBoxFrame : public nsButtonBoxFrame |
michael@0 | 18 | { |
michael@0 | 19 | public: |
michael@0 | 20 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 21 | |
michael@0 | 22 | friend nsIFrame* NS_NewAutoRepeatBoxFrame(nsIPresShell* aPresShell, |
michael@0 | 23 | nsStyleContext* aContext); |
michael@0 | 24 | |
michael@0 | 25 | virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
michael@0 | 26 | |
michael@0 | 27 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 28 | nsIAtom* aAttribute, |
michael@0 | 29 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 30 | |
michael@0 | 31 | virtual nsresult HandleEvent(nsPresContext* aPresContext, |
michael@0 | 32 | WidgetGUIEvent* aEvent, |
michael@0 | 33 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 34 | |
michael@0 | 35 | NS_IMETHOD HandlePress(nsPresContext* aPresContext, |
michael@0 | 36 | WidgetGUIEvent* aEvent, |
michael@0 | 37 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 38 | |
michael@0 | 39 | NS_IMETHOD HandleRelease(nsPresContext* aPresContext, |
michael@0 | 40 | WidgetGUIEvent* aEvent, |
michael@0 | 41 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 42 | |
michael@0 | 43 | protected: |
michael@0 | 44 | nsAutoRepeatBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext): |
michael@0 | 45 | nsButtonBoxFrame(aPresShell, aContext) {} |
michael@0 | 46 | |
michael@0 | 47 | void StartRepeat() { |
michael@0 | 48 | if (IsActivatedOnHover()) { |
michael@0 | 49 | // No initial delay on hover. |
michael@0 | 50 | nsRepeatService::GetInstance()->Start(Notify, this, 0); |
michael@0 | 51 | } else { |
michael@0 | 52 | nsRepeatService::GetInstance()->Start(Notify, this); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | void StopRepeat() { |
michael@0 | 56 | nsRepeatService::GetInstance()->Stop(Notify, this); |
michael@0 | 57 | } |
michael@0 | 58 | void Notify(); |
michael@0 | 59 | static void Notify(void* aData) { |
michael@0 | 60 | static_cast<nsAutoRepeatBoxFrame*>(aData)->Notify(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | bool mTrustedEvent; |
michael@0 | 64 | |
michael@0 | 65 | bool IsActivatedOnHover(); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | nsIFrame* |
michael@0 | 69 | NS_NewAutoRepeatBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 70 | { |
michael@0 | 71 | return new (aPresShell) nsAutoRepeatBoxFrame (aPresShell, aContext); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | NS_IMPL_FRAMEARENA_HELPERS(nsAutoRepeatBoxFrame) |
michael@0 | 75 | |
michael@0 | 76 | nsresult |
michael@0 | 77 | nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext, |
michael@0 | 78 | WidgetGUIEvent* aEvent, |
michael@0 | 79 | nsEventStatus* aEventStatus) |
michael@0 | 80 | { |
michael@0 | 81 | NS_ENSURE_ARG_POINTER(aEventStatus); |
michael@0 | 82 | if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { |
michael@0 | 83 | return NS_OK; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | switch(aEvent->message) |
michael@0 | 87 | { |
michael@0 | 88 | // repeat mode may be "hover" for repeating while the mouse is hovering |
michael@0 | 89 | // over the element, otherwise repetition is done while the element is |
michael@0 | 90 | // active (pressed). |
michael@0 | 91 | case NS_MOUSE_ENTER: |
michael@0 | 92 | case NS_MOUSE_ENTER_SYNTH: |
michael@0 | 93 | if (IsActivatedOnHover()) { |
michael@0 | 94 | StartRepeat(); |
michael@0 | 95 | mTrustedEvent = aEvent->mFlags.mIsTrusted; |
michael@0 | 96 | } |
michael@0 | 97 | break; |
michael@0 | 98 | |
michael@0 | 99 | case NS_MOUSE_EXIT: |
michael@0 | 100 | case NS_MOUSE_EXIT_SYNTH: |
michael@0 | 101 | // always stop on mouse exit |
michael@0 | 102 | StopRepeat(); |
michael@0 | 103 | // Not really necessary but do this to be safe |
michael@0 | 104 | mTrustedEvent = false; |
michael@0 | 105 | break; |
michael@0 | 106 | |
michael@0 | 107 | case NS_MOUSE_CLICK: { |
michael@0 | 108 | WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); |
michael@0 | 109 | if (mouseEvent->IsLeftClickEvent()) { |
michael@0 | 110 | // skip button frame handling to prevent click handling |
michael@0 | 111 | return nsBoxFrame::HandleEvent(aPresContext, mouseEvent, aEventStatus); |
michael@0 | 112 | } |
michael@0 | 113 | break; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | NS_IMETHODIMP |
michael@0 | 121 | nsAutoRepeatBoxFrame::HandlePress(nsPresContext* aPresContext, |
michael@0 | 122 | WidgetGUIEvent* aEvent, |
michael@0 | 123 | nsEventStatus* aEventStatus) |
michael@0 | 124 | { |
michael@0 | 125 | if (!IsActivatedOnHover()) { |
michael@0 | 126 | StartRepeat(); |
michael@0 | 127 | mTrustedEvent = aEvent->mFlags.mIsTrusted; |
michael@0 | 128 | DoMouseClick(aEvent, mTrustedEvent); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | return NS_OK; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | NS_IMETHODIMP |
michael@0 | 135 | nsAutoRepeatBoxFrame::HandleRelease(nsPresContext* aPresContext, |
michael@0 | 136 | WidgetGUIEvent* aEvent, |
michael@0 | 137 | nsEventStatus* aEventStatus) |
michael@0 | 138 | { |
michael@0 | 139 | if (!IsActivatedOnHover()) { |
michael@0 | 140 | StopRepeat(); |
michael@0 | 141 | } |
michael@0 | 142 | return NS_OK; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | nsresult |
michael@0 | 146 | nsAutoRepeatBoxFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 147 | nsIAtom* aAttribute, |
michael@0 | 148 | int32_t aModType) |
michael@0 | 149 | { |
michael@0 | 150 | if (aAttribute == nsGkAtoms::type) { |
michael@0 | 151 | StopRepeat(); |
michael@0 | 152 | } |
michael@0 | 153 | return NS_OK; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | void |
michael@0 | 157 | nsAutoRepeatBoxFrame::Notify() |
michael@0 | 158 | { |
michael@0 | 159 | DoMouseClick(nullptr, mTrustedEvent); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | void |
michael@0 | 163 | nsAutoRepeatBoxFrame::DestroyFrom(nsIFrame* aDestructRoot) |
michael@0 | 164 | { |
michael@0 | 165 | // Ensure our repeat service isn't going... it's possible that a scrollbar can disappear out |
michael@0 | 166 | // from under you while you're in the process of scrolling. |
michael@0 | 167 | StopRepeat(); |
michael@0 | 168 | nsButtonBoxFrame::DestroyFrom(aDestructRoot); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | bool |
michael@0 | 172 | nsAutoRepeatBoxFrame::IsActivatedOnHover() |
michael@0 | 173 | { |
michael@0 | 174 | return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::repeat, |
michael@0 | 175 | nsGkAtoms::hover, eCaseMatters); |
michael@0 | 176 | } |