diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-14 23:17:20 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-14 23:17:20 +0000 |
commit | 2c831b235ec39e7e4258cfd93b735de06f079a0e (patch) | |
tree | f0a49df25f1d7736bd8483de7cf09794fc06f055 /views | |
parent | 05a1ba49bd770a52a3a84aa2ce6241b0e538d7da (diff) | |
download | chromium_src-2c831b235ec39e7e4258cfd93b735de06f079a0e.zip chromium_src-2c831b235ec39e7e4258cfd93b735de06f079a0e.tar.gz chromium_src-2c831b235ec39e7e4258cfd93b735de06f079a0e.tar.bz2 |
Clean up some event code:
Update some RootView event construction.
Fixup some *MouseExited/OnLeaveNotify codepaths.
Normalize event argument names.
Move View::ConvertPoint*Ancestor defs to private section.
Review URL: http://codereview.chromium.org/6685018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78121 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
25 files changed, 284 insertions, 299 deletions
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc index 7bc5910..cdd93c3 100644 --- a/views/controls/button/button_dropdown.cc +++ b/views/controls/button/button_dropdown.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -41,12 +41,12 @@ ButtonDropDown::~ButtonDropDown() { // //////////////////////////////////////////////////////////////////////////////// -bool ButtonDropDown::OnMousePressed(const MouseEvent& e) { - if (IsEnabled() && IsTriggerableEvent(e) && HitTest(e.location())) { +bool ButtonDropDown::OnMousePressed(const MouseEvent& event) { + if (IsEnabled() && IsTriggerableEvent(event) && HitTest(event.location())) { // Store the y pos of the mouse coordinates so we can use them later to // determine if the user dragged the mouse down (which should pop up the // drag down menu immediately, instead of waiting for the timer) - y_position_on_lbuttondown_ = e.y(); + y_position_on_lbuttondown_ = event.y(); // Schedule a task that will show the menu. MessageLoop::current()->PostDelayedTask(FROM_HERE, @@ -54,37 +54,37 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& e) { GetWidget()->GetNativeView()), kMenuTimerDelay); } - return ImageButton::OnMousePressed(e); + return ImageButton::OnMousePressed(event); } -void ButtonDropDown::OnMouseReleased(const MouseEvent& e, bool canceled) { +void ButtonDropDown::OnMouseReleased(const MouseEvent& event, bool canceled) { // Showing the drop down results in a MouseReleased with a canceled drag, we // need to ignore it. - if (!canceled && (IsTriggerableEvent(e) || - (e.IsRightMouseButton() && !HitTest(e.location())))) { - ImageButton::OnMouseReleased(e, canceled); + if (!canceled && (IsTriggerableEvent(event) || + (event.IsRightMouseButton() && !HitTest(event.location())))) { + ImageButton::OnMouseReleased(event, canceled); } if (canceled) return; - if (IsTriggerableEvent(e)) + if (IsTriggerableEvent(event)) show_menu_factory_.RevokeAll(); - if (IsEnabled() && e.IsRightMouseButton() && HitTest(e.location())) { + if (IsEnabled() && event.IsRightMouseButton() && HitTest(event.location())) { show_menu_factory_.RevokeAll(); ShowDropDownMenu(GetWidget()->GetNativeView()); } } -bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) { - bool result = ImageButton::OnMouseDragged(e); +bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) { + bool result = ImageButton::OnMouseDragged(event); if (!show_menu_factory_.empty()) { // If the mouse is dragged to a y position lower than where it was when // clicked then we should not wait for the menu to appear but show // it immediately. - if (e.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { + if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { show_menu_factory_.RevokeAll(); ShowDropDownMenu(GetWidget()->GetNativeView()); } @@ -93,7 +93,7 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) { return result; } -void ButtonDropDown::OnMouseExited(const MouseEvent& e) { +void ButtonDropDown::OnMouseExited(const MouseEvent& event) { // Starting a drag results in a MouseExited, we need to ignore it. // A right click release triggers an exit event. We want to // remain in a PUSHED state until the drop down menu closes. @@ -114,11 +114,11 @@ void ButtonDropDown::ShowContextMenu(const gfx::Point& p, SetState(BS_HOT); } -bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& e) { +bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& event) { // Enter PUSHED state on press with Left or Right mouse button. Remain // in this state while the context menu is open. return ((ui::EF_LEFT_BUTTON_DOWN | - ui::EF_RIGHT_BUTTON_DOWN) & e.flags()) != 0; + ui::EF_RIGHT_BUTTON_DOWN) & event.flags()) != 0; } void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h index 32f2c5c..fe558e1 100644 --- a/views/controls/button/button_dropdown.h +++ b/views/controls/button/button_dropdown.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,22 +30,22 @@ class ButtonDropDown : public ImageButton { private: // Overridden from CustomButton - virtual bool OnMousePressed(const MouseEvent& e); - virtual void OnMouseReleased(const MouseEvent& e, bool canceled); - virtual bool OnMouseDragged(const MouseEvent& e); - virtual void OnMouseExited(const MouseEvent& e); + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; // Overridden from View. Used to display the right-click menu, as triggered // by the keyboard, for instance. Using the member function ShowDropDownMenu // for the actual display. virtual void ShowContextMenu(const gfx::Point& p, - bool is_mouse_gesture); + bool is_mouse_gesture) OVERRIDE; // Overridden from CustomButton. Returns true if the button should become // pressed when a user holds the mouse down over the button. For this // implementation, both left and right mouse buttons can trigger a change // to the PUSHED state. - virtual bool ShouldEnterPushedState(const MouseEvent& e); + virtual bool ShouldEnterPushedState(const MouseEvent& event) OVERRIDE; // Internal function to show the dropdown menu void ShowDropDownMenu(gfx::NativeView window); diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 2a34cc5..45aea1c 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -122,32 +122,32 @@ void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) { // Our focus border is rendered by the label, so we don't do anything here. } -void Checkbox::OnMouseEntered(const MouseEvent& e) { - native_wrapper_->SetPushed(HitTestLabel(e)); +void Checkbox::OnMouseEntered(const MouseEvent& event) { + native_wrapper_->SetPushed(HitTestLabel(event)); } -void Checkbox::OnMouseMoved(const MouseEvent& e) { - native_wrapper_->SetPushed(HitTestLabel(e)); +void Checkbox::OnMouseMoved(const MouseEvent& event) { + native_wrapper_->SetPushed(HitTestLabel(event)); } -void Checkbox::OnMouseExited(const MouseEvent& e) { +void Checkbox::OnMouseExited(const MouseEvent& event) { native_wrapper_->SetPushed(false); } -bool Checkbox::OnMousePressed(const MouseEvent& e) { - native_wrapper_->SetPushed(HitTestLabel(e)); +bool Checkbox::OnMousePressed(const MouseEvent& event) { + native_wrapper_->SetPushed(HitTestLabel(event)); return true; } -void Checkbox::OnMouseReleased(const MouseEvent& e, bool canceled) { +void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) { native_wrapper_->SetPushed(false); - if (!canceled && HitTestLabel(e)) { + if (!canceled && HitTestLabel(event)) { SetChecked(!checked()); ButtonPressed(); } } -bool Checkbox::OnMouseDragged(const MouseEvent& e) { +bool Checkbox::OnMouseDragged(const MouseEvent& event) { return false; } @@ -193,8 +193,8 @@ void Checkbox::SetLabel(const std::wstring& label) { //////////////////////////////////////////////////////////////////////////////// // Checkbox, protected: -bool Checkbox::HitTestLabel(const MouseEvent& e) { - gfx::Point tmp(e.location()); +bool Checkbox::HitTestLabel(const MouseEvent& event) { + gfx::Point tmp(event.location()); ConvertPointToView(this, label_, &tmp); return label_->HitTest(tmp); } diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h index 801b0fd..75660b4 100644 --- a/views/controls/button/checkbox.h +++ b/views/controls/button/checkbox.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -47,12 +47,12 @@ class Checkbox : public NativeButton { virtual void Layout() OVERRIDE; virtual void SetEnabled(bool enabled) OVERRIDE; virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; - virtual void OnMouseEntered(const MouseEvent& e) OVERRIDE; - virtual void OnMouseMoved(const MouseEvent& e) OVERRIDE; - virtual void OnMouseExited(const MouseEvent& e) OVERRIDE; - virtual bool OnMousePressed(const MouseEvent& e) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& e, bool canceled) OVERRIDE; - virtual bool OnMouseDragged(const MouseEvent& e) OVERRIDE; + virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; + virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; @@ -71,7 +71,7 @@ class Checkbox : public NativeButton { // Returns true if the event (in Checkbox coordinates) is within the bounds of // the label. - bool HitTestLabel(const MouseEvent& e); + bool HitTestLabel(const MouseEvent& event); private: // Called from the constructor to create and configure the checkbox label. diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index 04ee51a..2e7b4cdd 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -125,8 +125,8 @@ CustomButton::CustomButton(ButtonListener* listener) hover_animation_->SetSlideDuration(kHoverFadeDurationMs); } -bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { - return (triggerable_event_flags_ & e.flags()) != 0; +bool CustomButton::IsTriggerableEvent(const MouseEvent& event) { + return (triggerable_event_flags_ & event.flags()) != 0; } //////////////////////////////////////////////////////////////////////////////// @@ -143,9 +143,9 @@ bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { return true; } -bool CustomButton::OnMousePressed(const MouseEvent& e) { +bool CustomButton::OnMousePressed(const MouseEvent& event) { if (state_ != BS_DISABLED) { - if (ShouldEnterPushedState(e) && HitTest(e.location())) + if (ShouldEnterPushedState(event) && HitTest(event.location())) SetState(BS_PUSHED); if (request_focus_on_press_) RequestFocus(); @@ -153,74 +153,74 @@ bool CustomButton::OnMousePressed(const MouseEvent& e) { return true; } -bool CustomButton::OnMouseDragged(const MouseEvent& e) { +bool CustomButton::OnMouseDragged(const MouseEvent& event) { if (state_ != BS_DISABLED) { - if (HitTest(e.location())) - SetState(ShouldEnterPushedState(e) ? BS_PUSHED : BS_HOT); + if (HitTest(event.location())) + SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); else SetState(BS_NORMAL); } return true; } -void CustomButton::OnMouseReleased(const MouseEvent& e, bool canceled) { +void CustomButton::OnMouseReleased(const MouseEvent& event, bool canceled) { // Starting a drag results in a MouseReleased, we need to ignore it. if ((state_ == BS_DISABLED) || InDrag()) return; - if (!HitTest(e.location())) { + if (!HitTest(event.location())) { SetState(BS_NORMAL); return; } SetState(BS_HOT); - if (!canceled && IsTriggerableEvent(e)) { - NotifyClick(e); + if (!canceled && IsTriggerableEvent(event)) { + NotifyClick(event); // NOTE: We may be deleted at this point (by the listener's notification // handler). } } -void CustomButton::OnMouseEntered(const MouseEvent& e) { +void CustomButton::OnMouseEntered(const MouseEvent& event) { if (state_ != BS_DISABLED) SetState(BS_HOT); } -void CustomButton::OnMouseMoved(const MouseEvent& e) { +void CustomButton::OnMouseMoved(const MouseEvent& event) { if (state_ != BS_DISABLED) - SetState(HitTest(e.location()) ? BS_HOT : BS_NORMAL); + SetState(HitTest(event.location()) ? BS_HOT : BS_NORMAL); } -void CustomButton::OnMouseExited(const MouseEvent& e) { +void CustomButton::OnMouseExited(const MouseEvent& event) { // Starting a drag results in a MouseExited, we need to ignore it. if (state_ != BS_DISABLED && !InDrag()) SetState(BS_NORMAL); } -bool CustomButton::OnKeyPressed(const KeyEvent& e) { +bool CustomButton::OnKeyPressed(const KeyEvent& event) { if (state_ == BS_DISABLED) return false; // Space sets button state to pushed. Enter clicks the button. This matches // the Windows native behavior of buttons, where Space clicks the button on // KeyRelease and Enter clicks the button on KeyPressed. - if (e.key_code() == ui::VKEY_SPACE) { + if (event.key_code() == ui::VKEY_SPACE) { SetState(BS_PUSHED); - } else if (e.key_code() == ui::VKEY_RETURN) { + } else if (event.key_code() == ui::VKEY_RETURN) { SetState(BS_NORMAL); - NotifyClick(e); + NotifyClick(event); } else { return false; } return true; } -bool CustomButton::OnKeyReleased(const KeyEvent& e) { - if ((state_ == BS_DISABLED) || (e.key_code() != ui::VKEY_SPACE)) +bool CustomButton::OnKeyReleased(const KeyEvent& event) { + if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) return false; SetState(BS_NORMAL); - NotifyClick(e); + NotifyClick(event); return true; } @@ -271,8 +271,8 @@ void CustomButton::AnimationProgressed(const ui::Animation* animation) { SchedulePaint(); } -bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { - return IsTriggerableEvent(e); +bool CustomButton::ShouldEnterPushedState(const MouseEvent& event) { + return IsTriggerableEvent(event); } } // namespace views diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h index 6dcabc9..3f6f22a 100644 --- a/views/controls/button/custom_button.h +++ b/views/controls/button/custom_button.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -87,18 +87,18 @@ class CustomButton : public Button, // Returns true if the event is one that can trigger notifying the listener. // This implementation returns true if the left mouse button is down. - virtual bool IsTriggerableEvent(const MouseEvent& e); + virtual bool IsTriggerableEvent(const MouseEvent& event); // Overridden from View: virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; - virtual bool OnMousePressed(const MouseEvent& e) OVERRIDE; - virtual bool OnMouseDragged(const MouseEvent& e) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& e, bool canceled) OVERRIDE; - virtual void OnMouseEntered(const MouseEvent& e) OVERRIDE; - virtual void OnMouseMoved(const MouseEvent& e) OVERRIDE; - virtual void OnMouseExited(const MouseEvent& e) OVERRIDE; - virtual bool OnKeyPressed(const KeyEvent& e) OVERRIDE; - virtual bool OnKeyReleased(const KeyEvent& e) OVERRIDE; + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; + virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; + virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; + virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE; virtual void OnDragDone() OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) OVERRIDE; @@ -114,8 +114,8 @@ class CustomButton : public Button, // Returns true if the button should become pressed when the user // holds the mouse down over the button. For this implementation, - // we simply return IsTriggerableEvent(e). - virtual bool ShouldEnterPushedState(const MouseEvent& e); + // we simply return IsTriggerableEvent(event). + virtual bool ShouldEnterPushedState(const MouseEvent& event); // The button state (defined in implementation) ButtonState state_; diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index a3859ba..822ca39 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -188,13 +188,13 @@ bool MenuButton::Activate() { return true; } -bool MenuButton::OnMousePressed(const MouseEvent& e) { +bool MenuButton::OnMousePressed(const MouseEvent& event) { RequestFocus(); if (state() != BS_DISABLED) { // If we're draggable (GetDragOperations returns a non-zero value), then // don't pop on press, instead wait for release. - if (e.IsOnlyLeftMouseButton() && HitTest(e.location()) && - GetDragOperations(e.location()) == ui::DragDropTypes::DRAG_NONE) { + if (event.IsOnlyLeftMouseButton() && HitTest(event.location()) && + GetDragOperations(event.location()) == ui::DragDropTypes::DRAG_NONE) { TimeDelta delta = Time::Now() - menu_closed_time_; int64 delta_in_milliseconds = delta.InMilliseconds(); if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) { @@ -205,23 +205,22 @@ bool MenuButton::OnMousePressed(const MouseEvent& e) { return true; } -void MenuButton::OnMouseReleased(const MouseEvent& e, - bool canceled) { +void MenuButton::OnMouseReleased(const MouseEvent& event, bool canceled) { // Explicitly test for left mouse button to show the menu. If we tested for // !IsTriggerableEvent it could lead to a situation where we end up showing // the menu and context menu (this would happen if the right button is not // triggerable and there's a context menu). - if (GetDragOperations(e.location()) != ui::DragDropTypes::DRAG_NONE && + if (GetDragOperations(event.location()) != ui::DragDropTypes::DRAG_NONE && state() != BS_DISABLED && !canceled && !InDrag() && - e.IsOnlyLeftMouseButton() && HitTest(e.location())) { + event.IsOnlyLeftMouseButton() && HitTest(event.location())) { Activate(); } else { - TextButton::OnMouseReleased(e, canceled); + TextButton::OnMouseReleased(event, canceled); } } -bool MenuButton::OnKeyPressed(const KeyEvent& e) { - switch (e.key_code()) { +bool MenuButton::OnKeyPressed(const KeyEvent& event) { + switch (event.key_code()) { case ui::VKEY_SPACE: case ui::VKEY_RETURN: case ui::VKEY_UP: @@ -237,7 +236,7 @@ bool MenuButton::OnKeyPressed(const KeyEvent& e) { return false; } -bool MenuButton::OnKeyReleased(const KeyEvent& e) { +bool MenuButton::OnKeyReleased(const KeyEvent& event) { // Override CustomButton's implementation, which presses the button when // you press space and clicks it when you release space. For a MenuButton // we always activate the menu on key press. diff --git a/views/controls/button/menu_button.h b/views/controls/button/menu_button.h index eb5ca9c..d9622e4 100644 --- a/views/controls/button/menu_button.h +++ b/views/controls/button/menu_button.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -51,17 +51,17 @@ class MenuButton : public TextButton { // These methods are overriden to implement a simple push button // behavior. - virtual bool OnMousePressed(const MouseEvent& e); - virtual void OnMouseReleased(const MouseEvent& e, bool canceled); - virtual void OnMouseExited(const MouseEvent& event); - virtual bool OnKeyPressed(const KeyEvent& e); - virtual bool OnKeyReleased(const KeyEvent& e); + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; + virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; + virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE; // Accessibility accessors, overridden from View. virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // Returns views/MenuButton. - virtual std::string GetClassName() const; + virtual std::string GetClassName() const OVERRIDE; // Accessors for menu_offset_. const gfx::Point& menu_offset() const { diff --git a/views/controls/label.cc b/views/controls/label.cc index 21510af..c422ad0 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -200,8 +200,8 @@ bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { return false; } -void Label::OnMouseMoved(const MouseEvent& e) { - UpdateContainsMouse(e); +void Label::OnMouseMoved(const MouseEvent& event) { + UpdateContainsMouse(event); } void Label::OnMouseEntered(const MouseEvent& event) { diff --git a/views/controls/label.h b/views/controls/label.h index 0a2118e..7d8c64d 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -153,7 +153,7 @@ class Label : public View { // Mouse enter/exit are overridden to render mouse over background color. // These invoke SetContainsMouse as necessary. - virtual void OnMouseMoved(const MouseEvent& e) OVERRIDE; + virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 62f41e5..baabf69 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1025,13 +1025,14 @@ void MenuController::Accept(MenuItemView* item, int mouse_event_flags) { result_mouse_event_flags_ = mouse_event_flags; } -bool MenuController::ShowSiblingMenu(SubmenuView* source, const MouseEvent& e) { +bool MenuController::ShowSiblingMenu(SubmenuView* source, + const MouseEvent& event) { if (!menu_stack_.empty() || !menu_button_) return false; View* source_view = source->GetScrollViewContainer(); - if (e.x() >= 0 && e.x() < source_view->width() && e.y() >= 0 && - e.y() < source_view->height()) { + if (event.x() >= 0 && event.x() < source_view->width() && event.y() >= 0 && + event.y() < source_view->height()) { // The mouse is over the menu, no need to continue. return false; } @@ -1042,7 +1043,7 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source, const MouseEvent& e) { // The user moved the mouse outside the menu and over the owning window. See // if there is a sibling menu we should show. - gfx::Point screen_point(e.location()); + gfx::Point screen_point(event.location()); View::ConvertPointToScreen(source_view, &screen_point); MenuItemView::AnchorPosition anchor; bool has_mnemonics; @@ -1787,10 +1788,9 @@ void MenuController::UpdateActiveMouseView(SubmenuView* event_source, } if (target != active_mouse_view_) { if (active_mouse_view_) { + // TODO(msw): Revise api and uses with OnMouseCaptureLost (like ui/views). // Send a mouse release with cancel set to true. - MouseEvent release_event(ui::ET_MOUSE_RELEASED, -1, -1, 0); - active_mouse_view_->OnMouseReleased(release_event, true); - + active_mouse_view_->OnMouseReleased(event, true); active_mouse_view_ = NULL; } active_mouse_view_ = target; diff --git a/views/controls/menu/menu_controller.h b/views/controls/menu/menu_controller.h index dfd68b4..3838c45 100644 --- a/views/controls/menu/menu_controller.h +++ b/views/controls/menu/menu_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -238,7 +238,7 @@ class MenuController : public MessageLoopForUI::Dispatcher { // when blocking. This schedules the loop to quit. void Accept(MenuItemView* item, int mouse_event_flags); - bool ShowSiblingMenu(SubmenuView* source, const MouseEvent& e); + bool ShowSiblingMenu(SubmenuView* source, const MouseEvent& event); // Closes all menus, including any menus of nested invocations of Run. void CloseAllNestedMenus(); diff --git a/views/controls/menu/menu_host_root_view.cc b/views/controls/menu/menu_host_root_view.cc index cc0124c..bb791fc 100644 --- a/views/controls/menu/menu_host_root_view.cc +++ b/views/controls/menu/menu_host_root_view.cc @@ -66,17 +66,17 @@ void MenuHostRootView::OnMouseMoved(const MouseEvent& event) { GetMenuController()->OnMouseMoved(submenu_, event); } -bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& e) { +bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) { // RootView::OnMouseWheel forwards to the focused view. We don't have a // focused view, so we need to override this then forward to the menu. - return submenu_->OnMouseWheel(e); + return submenu_->OnMouseWheel(event); } -void MenuHostRootView::ProcessOnMouseExited() { +void MenuHostRootView::OnMouseExited(const MouseEvent& event) { if (suspend_events_) return; - RootView::ProcessOnMouseExited(); + RootView::OnMouseExited(event); } MenuController* MenuHostRootView::GetMenuController() { diff --git a/views/controls/menu/menu_host_root_view.h b/views/controls/menu/menu_host_root_view.h index 00648b4..f989170 100644 --- a/views/controls/menu/menu_host_root_view.h +++ b/views/controls/menu/menu_host_root_view.h @@ -32,8 +32,8 @@ class MenuHostRootView : public RootView { virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; - virtual bool OnMouseWheel(const MouseWheelEvent& e) OVERRIDE; - virtual void ProcessOnMouseExited() OVERRIDE; + virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; private: // Returns the MenuController for this MenuHostRootView. diff --git a/views/controls/scrollbar/bitmap_scroll_bar.h b/views/controls/scrollbar/bitmap_scroll_bar.h index d0138b4..839e872 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.h +++ b/views/controls/scrollbar/bitmap_scroll_bar.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -95,33 +95,34 @@ class BitmapScrollBar : public ScrollBar, void ScrollByContentsOffset(int contents_offset); // View overrides: - virtual gfx::Size GetPreferredSize(); - virtual void OnPaint(gfx::Canvas* canvas); - virtual void Layout(); - virtual bool OnMousePressed(const MouseEvent& event); - virtual void OnMouseReleased(const MouseEvent& event, bool canceled); - virtual bool OnMouseWheel(const MouseWheelEvent& event); - virtual bool OnKeyPressed(const KeyEvent& event); + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void Layout() OVERRIDE; + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; + virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; // BaseButton::ButtonListener overrides: - virtual void ButtonPressed(Button* sender, const views::Event& event); + virtual void ButtonPressed(Button* sender, + const views::Event& event) OVERRIDE; // ScrollBar overrides: virtual void Update(int viewport_size, int content_size, - int contents_scroll_offset); - virtual int GetLayoutSize() const; - virtual int GetPosition() const; + int contents_scroll_offset) OVERRIDE; + virtual int GetLayoutSize() const OVERRIDE; + virtual int GetPosition() const OVERRIDE; // ContextMenuController overrides. virtual void ShowContextMenuForView(View* source, const gfx::Point& p, - bool is_mouse_gesture); + bool is_mouse_gesture) OVERRIDE; // Menu::Delegate overrides: - virtual std::wstring GetLabel(int id) const; - virtual bool IsCommandEnabled(int id) const; - virtual void ExecuteCommand(int id); + virtual std::wstring GetLabel(int id) const OVERRIDE; + virtual bool IsCommandEnabled(int id) const OVERRIDE; + virtual void ExecuteCommand(int id) OVERRIDE; private: // Called when the mouse is pressed down in the track area. diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 443cc6e..0cc8700 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -352,11 +352,11 @@ size_t NativeTextfieldWin::GetCursorPosition() const { return 0U; } -bool NativeTextfieldWin::HandleKeyPressed(const views::KeyEvent& e) { +bool NativeTextfieldWin::HandleKeyPressed(const views::KeyEvent& event) { return false; } -bool NativeTextfieldWin::HandleKeyReleased(const views::KeyEvent& e) { +bool NativeTextfieldWin::HandleKeyReleased(const views::KeyEvent& event) { return false; } diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h index bea98c2..7946a00 100644 --- a/views/controls/textfield/native_textfield_win.h +++ b/views/controls/textfield/native_textfield_win.h @@ -82,8 +82,8 @@ class NativeTextfieldWin virtual void GetSelectedRange(TextRange* range) const OVERRIDE; virtual void SelectRange(const TextRange& range) OVERRIDE; virtual size_t GetCursorPosition() const OVERRIDE; - virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; - virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; + virtual bool HandleKeyPressed(const views::KeyEvent& event) OVERRIDE; + virtual bool HandleKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual void HandleFocus() OVERRIDE; virtual void HandleBlur() OVERRIDE; diff --git a/views/events/event_gtk.cc b/views/events/event_gtk.cc index 8b29369..a3496c1 100644 --- a/views/events/event_gtk.cc +++ b/views/events/event_gtk.cc @@ -16,10 +16,14 @@ namespace { ui::EventType EventTypeFromNative(NativeEvent native_event) { // Add new event types as necessary. switch (native_event->type) { + case GDK_ENTER_NOTIFY: + return ui::ET_MOUSE_ENTERED; case GDK_KEY_PRESS: return ui::ET_KEY_PRESSED; case GDK_KEY_RELEASE: return ui::ET_KEY_RELEASED; + case GDK_LEAVE_NOTIFY: + return ui::ET_MOUSE_EXITED; case GDK_SCROLL: return ui::ET_MOUSEWHEEL; default: diff --git a/views/view.cc b/views/view.cc index 7a706992..0547efb7 100644 --- a/views/view.cc +++ b/views/view.cc @@ -613,50 +613,6 @@ gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { return x_rect; } -bool View::ConvertPointForAncestor(const View* ancestor, - gfx::Point* point) const { - scoped_ptr<ui::Transform> trans(ui::Transform::Create()); - - // TODO(sad): Have some way of caching the transformation results. - - const View* v = this; - for (; v && v != ancestor; v = v->parent()) { - if (v->GetTransform().HasChange()) { - if (!trans->ConcatTransform(v->GetTransform())) - return false; - } - trans->ConcatTranslate(static_cast<float>(v->GetMirroredX()), - static_cast<float>(v->y())); - } - - if (trans->HasChange()) { - trans->TransformPoint(point); - } - - return v == ancestor; -} - -bool View::ConvertPointFromAncestor(const View* ancestor, - gfx::Point* point) const { - scoped_ptr<ui::Transform> trans(ui::Transform::Create()); - - const View* v = this; - for (; v && v != ancestor; v = v->parent()) { - if (v->GetTransform().HasChange()) { - if (!trans->ConcatTransform(v->GetTransform())) - return false; - } - trans->ConcatTranslate(static_cast<float>(v->GetMirroredX()), - static_cast<float>(v->y())); - } - - if (trans->HasChange()) { - trans->TransformPointReverse(point); - } - - return v == ancestor; -} - // Painting -------------------------------------------------------------------- void View::SchedulePaint() { @@ -781,24 +737,24 @@ bool View::HitTest(const gfx::Point& l) const { return false; } -bool View::OnMousePressed(const MouseEvent& e) { +bool View::OnMousePressed(const MouseEvent& event) { return false; } -bool View::OnMouseDragged(const MouseEvent& e) { +bool View::OnMouseDragged(const MouseEvent& event) { return false; } -void View::OnMouseReleased(const MouseEvent& e, bool canceled) { +void View::OnMouseReleased(const MouseEvent& event, bool canceled) { } -void View::OnMouseMoved(const MouseEvent& e) { +void View::OnMouseMoved(const MouseEvent& event) { } -void View::OnMouseEntered(const MouseEvent& e) { +void View::OnMouseEntered(const MouseEvent& event) { } -void View::OnMouseExited(const MouseEvent& e) { +void View::OnMouseExited(const MouseEvent& event) { } #if defined(TOUCH_UI) @@ -814,15 +770,15 @@ void View::SetMouseHandler(View *new_mouse_handler) { parent_->SetMouseHandler(new_mouse_handler); } -bool View::OnKeyPressed(const KeyEvent& e) { +bool View::OnKeyPressed(const KeyEvent& event) { return false; } -bool View::OnKeyReleased(const KeyEvent& e) { +bool View::OnKeyReleased(const KeyEvent& event) { return false; } -bool View::OnMouseWheel(const MouseWheelEvent& e) { +bool View::OnMouseWheel(const MouseWheelEvent& event) { return false; } @@ -927,7 +883,7 @@ void View::RequestFocus() { focus_manager->SetFocusedView(this); } -bool View::SkipDefaultKeyEventProcessing(const KeyEvent& e) { +bool View::SkipDefaultKeyEventProcessing(const KeyEvent& event) { return false; } @@ -1437,42 +1393,87 @@ void View::ConvertPointToView(const View* src, } } +bool View::ConvertPointForAncestor(const View* ancestor, + gfx::Point* point) const { + scoped_ptr<ui::Transform> trans(ui::Transform::Create()); + + // TODO(sad): Have some way of caching the transformation results. + + const View* v = this; + for (; v && v != ancestor; v = v->parent()) { + if (v->GetTransform().HasChange()) { + if (!trans->ConcatTransform(v->GetTransform())) + return false; + } + trans->ConcatTranslate(static_cast<float>(v->GetMirroredX()), + static_cast<float>(v->y())); + } + + if (trans->HasChange()) { + trans->TransformPoint(point); + } + + return v == ancestor; +} + +bool View::ConvertPointFromAncestor(const View* ancestor, + gfx::Point* point) const { + scoped_ptr<ui::Transform> trans(ui::Transform::Create()); + + const View* v = this; + for (; v && v != ancestor; v = v->parent()) { + if (v->GetTransform().HasChange()) { + if (!trans->ConcatTransform(v->GetTransform())) + return false; + } + trans->ConcatTranslate(static_cast<float>(v->GetMirroredX()), + static_cast<float>(v->y())); + } + + if (trans->HasChange()) { + trans->TransformPointReverse(point); + } + + return v == ancestor; +} + // Input ----------------------------------------------------------------------- -bool View::ProcessMousePressed(const MouseEvent& e, DragInfo* drag_info) { +bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) { const bool enabled = IsEnabled(); int drag_operations = - (enabled && e.IsOnlyLeftMouseButton() && HitTest(e.location())) ? - GetDragOperations(e.location()) : 0; - ContextMenuController* context_menu_controller = e.IsRightMouseButton() ? + (enabled && event.IsOnlyLeftMouseButton() && HitTest(event.location())) ? + GetDragOperations(event.location()) : 0; + ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? context_menu_controller_ : 0; - const bool result = OnMousePressed(e); + const bool result = OnMousePressed(event); // WARNING: we may have been deleted, don't use any View variables. if (!enabled) return result; if (drag_operations != ui::DragDropTypes::DRAG_NONE) { - drag_info->PossibleDrag(e.location()); + drag_info->PossibleDrag(event.location()); return true; } return !!context_menu_controller || result; } -bool View::ProcessMouseDragged(const MouseEvent& e, DragInfo* drag_info) { +bool View::ProcessMouseDragged(const MouseEvent& event, DragInfo* drag_info) { // Copy the field, that way if we're deleted after drag and drop no harm is // done. ContextMenuController* context_menu_controller = context_menu_controller_; const bool possible_drag = drag_info->possible_drag; - if (possible_drag && ExceededDragThreshold(drag_info->start_pt.x() - e.x(), - drag_info->start_pt.y() - e.y())) { + if (possible_drag && ExceededDragThreshold( + drag_info->start_pt.x() - event.x(), + drag_info->start_pt.y() - event.y())) { if (!drag_controller_ || drag_controller_->CanStartDragForView( - this, drag_info->start_pt, e.location())) - DoDrag(e, drag_info->start_pt); + this, drag_info->start_pt, event.location())) + DoDrag(event, drag_info->start_pt); } else { - if (OnMouseDragged(e)) + if (OnMouseDragged(event)) return true; // Fall through to return value based on context menu controller. } @@ -1480,27 +1481,27 @@ bool View::ProcessMouseDragged(const MouseEvent& e, DragInfo* drag_info) { return (context_menu_controller != NULL) || possible_drag; } -void View::ProcessMouseReleased(const MouseEvent& e, bool canceled) { - if (!canceled && context_menu_controller_ && e.IsOnlyRightMouseButton()) { +void View::ProcessMouseReleased(const MouseEvent& event, bool canceled) { + if (!canceled && context_menu_controller_ && event.IsOnlyRightMouseButton()) { // Assume that if there is a context menu controller we won't be deleted // from mouse released. - gfx::Point location(e.location()); - OnMouseReleased(e, canceled); + gfx::Point location(event.location()); + OnMouseReleased(event, canceled); if (HitTest(location)) { ConvertPointToScreen(this, &location); ShowContextMenu(location, true); } } else { - OnMouseReleased(e, canceled); + OnMouseReleased(event, canceled); } // WARNING: we may have been deleted. } #if defined(TOUCH_UI) -View::TouchStatus View::ProcessTouchEvent(const TouchEvent& e) { +View::TouchStatus View::ProcessTouchEvent(const TouchEvent& event) { // TODO(rjkroege): Implement a grab scheme similar to as // as is found in MousePressed. - return OnTouchEvent(e); + return OnTouchEvent(event); } #endif @@ -1635,7 +1636,7 @@ void View::UpdateTooltip() { // Drag and drop --------------------------------------------------------------- -void View::DoDrag(const MouseEvent& e, const gfx::Point& press_pt) { +void View::DoDrag(const MouseEvent& event, const gfx::Point& press_pt) { int drag_operations = GetDragOperations(press_pt); if (drag_operations == ui::DragDropTypes::DRAG_NONE) return; diff --git a/views/view.h b/views/view.h index 1c059f1..8117ab2 100644 --- a/views/view.h +++ b/views/view.h @@ -625,7 +625,7 @@ class View : public AcceleratorTarget { // The event is in the receiver's coordinate system. // // Default implementation does nothing. Override as needed. - virtual void OnMouseMoved(const MouseEvent& e); + virtual void OnMouseMoved(const MouseEvent& event); // This method is invoked when the mouse enters this control. // @@ -667,14 +667,14 @@ class View : public AcceleratorTarget { // Subclasser should return true if the event has been processed and false // otherwise. If the event has not been processed, the parent will be given a // chance. - virtual bool OnKeyPressed(const KeyEvent& e); - virtual bool OnKeyReleased(const KeyEvent& e); + virtual bool OnKeyPressed(const KeyEvent& event); + virtual bool OnKeyReleased(const KeyEvent& event); // Invoked when the user uses the mousewheel. Implementors should return true // if the event has been processed and false otherwise. This message is sent // if the view is focused. If the event has not been processed, the parent // will be given a chance. - virtual bool OnMouseWheel(const MouseWheelEvent& e); + virtual bool OnMouseWheel(const MouseWheelEvent& event); // Accelerators -------------------------------------------------------------- @@ -756,7 +756,7 @@ class View : public AcceleratorTarget { // have it processed as an accelerator (if any) or as a tab traversal (if the // key event is for the TAB key). In that case, OnKeyPressed will // subsequently be invoked for that event. - virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e); + virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event); // Subclasses that contain traversable children that are not directly // accessible through the children hierarchy should return the associated @@ -1215,14 +1215,14 @@ class View : public AcceleratorTarget { // RootView invokes these. These in turn invoke the appropriate OnMouseXXX // method. If a drag is detected, DoDrag is invoked. - bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info); - bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info); - void ProcessMouseReleased(const MouseEvent& e, bool canceled); + bool ProcessMousePressed(const MouseEvent& event, DragInfo* drop_info); + bool ProcessMouseDragged(const MouseEvent& event, DragInfo* drop_info); + void ProcessMouseReleased(const MouseEvent& event, bool canceled); #if defined(TOUCH_UI) // RootView will invoke this with incoming TouchEvents. Returns the // the result of OnTouchEvent. - TouchStatus ProcessTouchEvent(const TouchEvent& e); + TouchStatus ProcessTouchEvent(const TouchEvent& event); #endif // Accelerators -------------------------------------------------------------- @@ -1266,7 +1266,7 @@ class View : public AcceleratorTarget { // Starts a drag and drop operation originating from this view. This invokes // WriteDragData to write the data and GetDragOperations to determine the // supported drag operations. When done, OnDragDone is invoked. - void DoDrag(const MouseEvent& e, const gfx::Point& press_pt); + void DoDrag(const MouseEvent& event, const gfx::Point& press_pt); ////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 32805df..0ce608c 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -91,14 +91,6 @@ void RootView::ProcessMouseDragCanceled() { } } -void RootView::ProcessOnMouseExited() { - if (mouse_move_handler_ != NULL) { - MouseEvent exited_event(ui::ET_MOUSE_EXITED, 0, 0, 0); - mouse_move_handler_->OnMouseExited(exited_event); - mouse_move_handler_ = NULL; - } -} - bool RootView::ProcessKeyEvent(const KeyEvent& event) { bool consumed = false; @@ -171,6 +163,13 @@ Widget* RootView::GetWidget() { return const_cast<Widget*>(const_cast<const RootView*>(this)->GetWidget()); } +void RootView::OnMouseExited(const MouseEvent& event) { + if (mouse_move_handler_ != NULL) { + mouse_move_handler_->OnMouseExited(event); + mouse_move_handler_ = NULL; + } +} + bool RootView::OnMousePressed(const MouseEvent& event) { MouseEvent e(event, this); @@ -290,33 +289,20 @@ void RootView::OnMouseMoved(const MouseEvent& event) { v = v->parent(); if (v && v != this) { if (v != mouse_move_handler_) { - if (mouse_move_handler_ != NULL) { - MouseEvent exited_event(ui::ET_MOUSE_EXITED, 0, 0, 0); - mouse_move_handler_->OnMouseExited(exited_event); - } - + if (mouse_move_handler_ != NULL) + mouse_move_handler_->OnMouseExited(e); mouse_move_handler_ = v; - - MouseEvent entered_event(ui::ET_MOUSE_ENTERED, - this, - mouse_move_handler_, - e.location(), - 0); + MouseEvent entered_event(e, this, mouse_move_handler_); mouse_move_handler_->OnMouseEntered(entered_event); } - MouseEvent moved_event(ui::ET_MOUSE_MOVED, - this, - mouse_move_handler_, - e.location(), - 0); + MouseEvent moved_event(e, this, mouse_move_handler_); mouse_move_handler_->OnMouseMoved(moved_event); gfx::NativeCursor cursor = mouse_move_handler_->GetCursorForPoint( moved_event.type(), moved_event.location()); widget_->SetCursor(cursor); } else if (mouse_move_handler_ != NULL) { - MouseEvent exited_event(ui::ET_MOUSE_EXITED, 0, 0, 0); - mouse_move_handler_->OnMouseExited(exited_event); + mouse_move_handler_->OnMouseExited(e); widget_->SetCursor(NULL); } } @@ -435,49 +421,39 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { // Coordinate conversion ------------------------------------------------------- -bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, - gfx::Point* p) { - // - // If the mouse_handler was set explicitly, we need to keep - // sending events even if it was re-parented in a different - // window. (a non explicit mouse handler is automatically - // cleared when the control is removed from the hierarchy) +bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, gfx::Point* p) { + // If the mouse_handler was set explicitly, keep sending events even if it was + // re-parented in a different window. (a non explicit mouse handler is + // automatically cleared when the control is removed from the hierarchy) + *p = l; if (explicit_mouse_handler_) { - if (mouse_pressed_handler_->GetWidget()) { - *p = l; - ConvertPointToScreen(this, p); + // If the mouse_pressed_handler_ is not connected, we send the + // event in screen coordinate system + ConvertPointToScreen(this, p); + if (mouse_pressed_handler_->GetWidget()) ConvertPointToView(NULL, mouse_pressed_handler_, p); - } else { - // If the mouse_pressed_handler_ is not connected, we send the - // event in screen coordinate system - *p = l; - ConvertPointToScreen(this, p); - return true; - } - } else { - *p = l; + } else ConvertPointToView(this, mouse_pressed_handler_, p); - } return true; } // Input ----------------------------------------------------------------------- -void RootView::UpdateCursor(const MouseEvent& e) { +void RootView::UpdateCursor(const MouseEvent& event) { gfx::NativeCursor cursor = NULL; - View* v = GetEventHandlerForPoint(e.location()); + View* v = GetEventHandlerForPoint(event.location()); if (v && v != this) { - gfx::Point l(e.location()); + gfx::Point l(event.location()); View::ConvertPointToView(this, v, &l); - cursor = v->GetCursorForPoint(e.type(), l); + cursor = v->GetCursorForPoint(event.type(), l); } widget_->SetCursor(cursor); } -void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { - last_mouse_event_flags_ = e.flags(); - last_mouse_event_x_ = e.x(); - last_mouse_event_y_ = e.y(); +void RootView::SetMouseLocationAndFlags(const MouseEvent& event) { + last_mouse_event_flags_ = event.flags(); + last_mouse_event_x_ = event.x(); + last_mouse_event_y_ = event.y(); } } // namespace views diff --git a/views/widget/root_view.h b/views/widget/root_view.h index d9634b2..3eac199 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -63,10 +63,6 @@ class RootView : public View, // the system. Invokes OnMouseReleased with a value of true for canceled. void ProcessMouseDragCanceled(); - // Invoked by the Widget instance when the mouse moves outside of the Widget - // bounds. - virtual void ProcessOnMouseExited(); - // Process a key event. Send the event to the focused view and up the focus // path, and finally to the default keyboard handler, until someone consumes // it. Returns whether anyone consumed the event. @@ -106,14 +102,15 @@ class RootView : public View, virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual const Widget* GetWidget() const OVERRIDE; virtual Widget* GetWidget() OVERRIDE; - virtual bool OnMousePressed(const MouseEvent& e) OVERRIDE; - virtual bool OnMouseDragged(const MouseEvent& e) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& e, bool canceled) OVERRIDE; - virtual void OnMouseMoved(const MouseEvent& e) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE; - virtual bool OnMouseWheel(const MouseWheelEvent& e) OVERRIDE; + virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; #if defined(TOUCH_UI) - virtual TouchStatus OnTouchEvent(const TouchEvent& e) OVERRIDE; + virtual TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; #endif virtual bool IsVisibleInRootView() const OVERRIDE; virtual std::string GetClassName() const OVERRIDE; @@ -148,12 +145,12 @@ class RootView : public View, // cursor during drag operations. The location of the mouse should be in the // current coordinate system (i.e. any necessary transformation should be // applied to the point prior to calling this). - void UpdateCursor(const MouseEvent& e); + void UpdateCursor(const MouseEvent& event); // Updates the last_mouse_* fields from e. The location of the mouse should be // in the current coordinate system (i.e. any necessary transformation should // be applied to the point prior to calling this). - void SetMouseLocationAndFlags(const MouseEvent& e); + void SetMouseLocationAndFlags(const MouseEvent& event); ////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index ec9ef0c..d60a0c9 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -1074,8 +1074,10 @@ gboolean WidgetGtk::OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event) { gboolean WidgetGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event) { last_mouse_event_was_move_ = false; - if (!has_capture_ && !is_mouse_down_) - GetRootView()->ProcessOnMouseExited(); + if (!has_capture_ && !is_mouse_down_) { + MouseEvent mouse_event(reinterpret_cast<GdkEvent*>(event)); + GetRootView()->OnMouseExited(mouse_event); + } return false; } diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 783c5ca..badb66f 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -675,7 +675,7 @@ LRESULT WidgetWin::OnMouseActivate(UINT message, LRESULT WidgetWin::OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) { tooltip_manager_->OnMouseLeave(); - ProcessMouseExited(); + ProcessMouseExited(message, w_param, l_param); return 0; } @@ -747,7 +747,7 @@ LRESULT WidgetWin::OnNCHitTest(const CPoint& pt) { LRESULT WidgetWin::OnNCMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) { - ProcessMouseExited(); + ProcessMouseExited(message, w_param, l_param); return 0; } @@ -977,9 +977,14 @@ bool WidgetWin::ProcessMouseMoved(UINT message, return true; } -void WidgetWin::ProcessMouseExited() { +void WidgetWin::ProcessMouseExited(UINT message, + WPARAM w_param, + LPARAM l_param) { last_mouse_event_was_move_ = false; - GetRootView()->ProcessOnMouseExited(); + MSG msg; + MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), + GET_Y_LPARAM(l_param)); + GetRootView()->OnMouseExited(MouseEvent(msg)); // Reset our tracking flag so that future mouse movement over this WidgetWin // results in a new tracking session. active_mouse_tracking_flags_ = 0; diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 67816e0..ba78268 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -400,7 +400,7 @@ class WidgetWin : public ui::WindowImpl, bool ProcessMousePressed(UINT message, WPARAM w_param, LPARAM l_param); bool ProcessMouseReleased(UINT message, WPARAM w_param, LPARAM l_param); bool ProcessMouseMoved(UINT message, WPARAM w_param, LPARAM l_param); - void ProcessMouseExited(); + void ProcessMouseExited(UINT message, WPARAM w_param, LPARAM l_param); // Called when a MSAA screen reader client is detected. virtual void OnScreenReaderDetected(); |