Bug 1455055 part 3. Clean up HandleEvent implementations in layout. r=masayuki

MozReview-Commit-ID: 7Irm8aAmeIt
This commit is contained in:
Boris Zbarsky 2018-04-20 00:49:29 -04:00
parent b198cf2c31
commit bac3f2e054
8 changed files with 47 additions and 53 deletions

View File

@ -2221,7 +2221,7 @@ nsLayoutUtils::HasPseudoStyle(nsIContent* aContent,
}
nsPoint
nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame)
nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(Event* aDOMEvent, nsIFrame* aFrame)
{
if (!aDOMEvent)
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);

View File

@ -44,7 +44,6 @@ class nsPresContext;
class nsIContent;
class nsAtom;
class nsIScrollableFrame;
class nsIDOMEvent;
class nsRegion;
class nsDisplayListBuilder;
enum class nsDisplayListBuilderMode : uint8_t;
@ -80,6 +79,7 @@ namespace dom {
class CanvasRenderingContext2D;
class DOMRectList;
class Element;
class Event;
class HTMLImageElement;
class HTMLCanvasElement;
class HTMLVideoElement;
@ -709,7 +709,7 @@ public:
* for some reason the coordinates for the mouse are not known (e.g.,
* the event is not a GUI event).
*/
static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent,
static nsPoint GetDOMEventCoordinatesRelativeTo(mozilla::dom::Event* aDOMEvent,
nsIFrame* aFrame);
/**

View File

@ -238,12 +238,11 @@ nsFileControlFrame::DnDListener::HandleEvent(Event* aEvent)
{
NS_ASSERTION(mFrame, "We should have been unregistered");
Event* event = aEvent->InternalDOMEvent();
if (event->DefaultPrevented()) {
if (aEvent->DefaultPrevented()) {
return NS_OK;
}
DragEvent* dragEvent = event->AsDragEvent();
DragEvent* dragEvent = aEvent->AsDragEvent();
if (!dragEvent) {
return NS_OK;
}

View File

@ -844,10 +844,10 @@ nsListControlFrame::PerformSelection(int32_t aClickedIndex,
//---------------------------------------------------------
bool
nsListControlFrame::HandleListSelection(nsIDOMEvent* aEvent,
nsListControlFrame::HandleListSelection(dom::Event* aEvent,
int32_t aClickedIndex)
{
MouseEvent* mouseEvent = aEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aEvent->AsMouseEvent();
bool isControl;
#ifdef XP_MACOSX
isControl = mouseEvent->MetaKey();
@ -1562,10 +1562,10 @@ nsListControlFrame::IsOptionDisabled(int32_t anIndex, bool &aIsDisabled)
// helper
//----------------------------------------------------------------------
bool
nsListControlFrame::IsLeftButton(nsIDOMEvent* aMouseEvent)
nsListControlFrame::IsLeftButton(dom::Event* aMouseEvent)
{
// only allow selection with the left button
MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
return mouseEvent && mouseEvent->Button() == 0;
}
@ -1603,11 +1603,11 @@ nsListControlFrame::CalcIntrinsicBSize(nscoord aBSizeOfARow,
// nsIDOMMouseListener
//----------------------------------------------------------------------
nsresult
nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
nsListControlFrame::MouseUp(dom::Event* aMouseEvent)
{
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
UpdateInListState(aMouseEvent);
@ -1702,7 +1702,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
}
void
nsListControlFrame::UpdateInListState(nsIDOMEvent* aEvent)
nsListControlFrame::UpdateInListState(dom::Event* aEvent)
{
if (!mComboboxFrame || !mComboboxFrame->IsDroppedDown())
return;
@ -1714,7 +1714,7 @@ nsListControlFrame::UpdateInListState(nsIDOMEvent* aEvent)
}
}
bool nsListControlFrame::IgnoreMouseEventForSelection(nsIDOMEvent* aEvent)
bool nsListControlFrame::IgnoreMouseEventForSelection(dom::Event* aEvent)
{
if (!mComboboxFrame)
return false;
@ -1745,8 +1745,8 @@ nsListControlFrame::FireMenuItemActiveEvent()
#endif
nsresult
nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
int32_t& aCurIndex)
nsListControlFrame::GetIndexFromDOMEvent(dom::Event* aMouseEvent,
int32_t& aCurIndex)
{
if (IgnoreMouseEventForSelection(aMouseEvent))
return NS_ERROR_FAILURE;
@ -1797,11 +1797,11 @@ FireShowDropDownEvent(nsIContent* aContent, bool aShow, bool aIsSourceTouchEvent
}
nsresult
nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
nsListControlFrame::MouseDown(dom::Event* aMouseEvent)
{
NS_ASSERTION(aMouseEvent != nullptr, "aMouseEvent is null.");
MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
UpdateInListState(aMouseEvent);
@ -1846,9 +1846,8 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
// Ignore the click that occurs on the option element when one is
// selected from the parent process popup.
if (mComboboxFrame->IsOpenInParentProcess()) {
nsCOMPtr<nsIDOMEventTarget> etarget;
aMouseEvent->GetTarget(getter_AddRefs(etarget));
nsCOMPtr<nsIContent> econtent = do_QueryInterface(etarget);
nsCOMPtr<nsIContent> econtent =
do_QueryInterface(aMouseEvent->GetTarget());
HTMLOptionElement* option = HTMLOptionElement::FromNodeOrNull(econtent);
if (option) {
return NS_OK;
@ -1884,14 +1883,11 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
//----------------------------------------------------------------------
// nsIDOMMouseMotionListener
//----------------------------------------------------------------------
nsresult
nsListControlFrame::MouseMove(nsIDOMEvent* aMouseEvent)
nsListControlFrame::MouseMove(dom::Event* aMouseEvent)
{
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_FAILURE);
UpdateInListState(aMouseEvent);
@ -1912,7 +1908,7 @@ nsListControlFrame::MouseMove(nsIDOMEvent* aMouseEvent)
}
nsresult
nsListControlFrame::DragMove(nsIDOMEvent* aMouseEvent)
nsListControlFrame::DragMove(dom::Event* aMouseEvent)
{
NS_ASSERTION(aMouseEvent, "aMouseEvent is null.");
@ -1925,7 +1921,7 @@ nsListControlFrame::DragMove(nsIDOMEvent* aMouseEvent)
if (selectedIndex == mEndSelectionIndex) {
return NS_OK;
}
MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
MouseEvent* mouseEvent = aMouseEvent->AsMouseEvent();
NS_ASSERTION(mouseEvent, "aMouseEvent is not a MouseEvent!");
bool isControl;
#ifdef XP_MACOSX
@ -2094,7 +2090,7 @@ nsListControlFrame::Shutdown()
}
void
nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent)
nsListControlFrame::DropDownToggleKey(dom::Event* aKeyEvent)
{
// Cocoa widgets do native popups, so don't try to show
// dropdowns there.
@ -2116,7 +2112,7 @@ nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent)
}
nsresult
nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
nsListControlFrame::KeyDown(dom::Event* aKeyEvent)
{
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
@ -2307,7 +2303,7 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
}
nsresult
nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
nsListControlFrame::KeyPress(dom::Event* aKeyEvent)
{
MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
@ -2538,9 +2534,7 @@ nsListEventListener::HandleEvent(dom::Event* aEvent)
return mFrame->nsListControlFrame::KeyPress(aEvent);
}
if (eventType.EqualsLiteral("mousedown")) {
bool defaultPrevented = false;
aEvent->GetDefaultPrevented(&defaultPrevented);
if (defaultPrevented) {
if (aEvent->DefaultPrevented()) {
return NS_OK;
}
return mFrame->nsListControlFrame::MouseDown(aEvent);

View File

@ -35,6 +35,7 @@ class nsListEventListener;
namespace mozilla {
namespace dom {
class Event;
class HTMLOptionElement;
class HTMLOptionsCollection;
} // namespace dom
@ -160,12 +161,12 @@ public:
* Mouse event listeners.
* @note These methods might destroy the frame, pres shell and other objects.
*/
nsresult MouseDown(nsIDOMEvent* aMouseEvent);
nsresult MouseUp(nsIDOMEvent* aMouseEvent);
nsresult MouseMove(nsIDOMEvent* aMouseEvent);
nsresult DragMove(nsIDOMEvent* aMouseEvent);
nsresult KeyDown(nsIDOMEvent* aKeyEvent);
nsresult KeyPress(nsIDOMEvent* aKeyEvent);
nsresult MouseDown(mozilla::dom::Event* aMouseEvent);
nsresult MouseUp(mozilla::dom::Event* aMouseEvent);
nsresult MouseMove(mozilla::dom::Event* aMouseEvent);
nsresult DragMove(mozilla::dom::Event* aMouseEvent);
nsresult KeyDown(mozilla::dom::Event* aKeyEvent);
nsresult KeyPress(mozilla::dom::Event* aKeyEvent);
/**
* Returns the options collection for mContent, if any.
@ -272,7 +273,7 @@ protected:
* Toggles (show/hide) the combobox dropdown menu.
* @note This method might destroy the frame, pres shell and other objects.
*/
void DropDownToggleKey(nsIDOMEvent* aKeyEvent);
void DropDownToggleKey(mozilla::dom::Event* aKeyEvent);
nsresult IsOptionDisabled(int32_t anIndex, bool &aIsDisabled);
/**
@ -294,13 +295,13 @@ protected:
*
* @param aPoint relative to this frame
*/
bool IgnoreMouseEventForSelection(nsIDOMEvent* aEvent);
bool IgnoreMouseEventForSelection(mozilla::dom::Event* aEvent);
/**
* If the dropdown is showing and the mouse has moved below our
* border-inner-edge, then set mItemSelectionStarted.
*/
void UpdateInListState(nsIDOMEvent* aEvent);
void UpdateInListState(mozilla::dom::Event* aEvent);
void AdjustIndexForDisabledOpt(int32_t aStartIndex, int32_t &anNewIndex,
int32_t aNumOptions, int32_t aDoAdjustInc, int32_t aDoAdjustIncNext);
@ -319,10 +320,11 @@ protected:
* @param aPoint the event point, in listcontrolframe coordinates
* @return NS_OK if it successfully found the selection
*/
nsresult GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent, int32_t& aCurIndex);
nsresult GetIndexFromDOMEvent(mozilla::dom::Event* aMouseEvent,
int32_t& aCurIndex);
bool CheckIfAllFramesHere();
bool IsLeftButton(nsIDOMEvent* aMouseEvent);
bool IsLeftButton(mozilla::dom::Event* aMouseEvent);
// guess at a row block size based on our own style.
nscoord CalcFallbackRowBSize(float aFontSizeInflation);
@ -365,7 +367,8 @@ protected:
/**
* @note This method might destroy the frame, pres shell and other objects.
*/
bool HandleListSelection(nsIDOMEvent * aDOMEvent, int32_t selectedIndex);
bool HandleListSelection(mozilla::dom::Event * aDOMEvent,
int32_t selectedIndex);
void InitSelectionRange(int32_t aClickedIndex);
void PostHandleKeyEvent(int32_t aNewIndex, uint32_t aCharCode,
bool aIsShift, bool aIsControlOrMeta);

View File

@ -122,9 +122,8 @@ ScrollbarActivity::HandleEvent(dom::Event* aEvent)
return NS_OK;
}
nsCOMPtr<nsIDOMEventTarget> target;
aEvent->GetOriginalTarget(getter_AddRefs(target));
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
nsCOMPtr<nsIContent> targetContent =
do_QueryInterface(aEvent->GetOriginalTarget());
HandleEventForScrollbar(type, targetContent, GetHorizontalScrollbar(),
&mHScrollbarHovered);

View File

@ -986,8 +986,7 @@ nsImageMap::HandleEvent(Event* aEvent)
"Unexpected event type");
//Set which one of our areas changed focus
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(
aEvent->InternalDOMEvent()->GetTarget());
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(aEvent->GetTarget());
if (!targetContent) {
return NS_OK;
}

View File

@ -108,7 +108,7 @@ enum eEventAction {
};
static eEventAction
GetActionForEvent(nsIDOMEvent* aEvent)
GetActionForEvent(Event* aEvent)
{
WidgetKeyboardEvent* keyEvent =
aEvent->WidgetEventPtr()->AsKeyboardEvent();
@ -160,7 +160,7 @@ NS_IMETHODIMP
nsPrintPreviewListener::HandleEvent(Event* aEvent)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(
aEvent ? aEvent->InternalDOMEvent()->GetOriginalTarget() : nullptr);
aEvent ? aEvent->GetOriginalTarget() : nullptr);
if (content && !content->IsXULElement()) {
eEventAction action = ::GetActionForEvent(aEvent);
switch (action) {