diff options
Diffstat (limited to 'views/controls')
26 files changed, 155 insertions, 169 deletions
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc index c2da598..7afdbd5 100644 --- a/views/controls/button/button_dropdown.cc +++ b/views/controls/button/button_dropdown.cc @@ -73,17 +73,12 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) { return result; } -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(event) || - (event.IsRightMouseButton() && !HitTest(event.location())))) { - ImageButton::OnMouseReleased(event, canceled); +void ButtonDropDown::OnMouseReleased(const MouseEvent& event) { + if (IsTriggerableEvent(event) || + (event.IsRightMouseButton() && !HitTest(event.location()))) { + ImageButton::OnMouseReleased(event); } - if (canceled) - return; - if (IsTriggerableEvent(event)) show_menu_factory_.RevokeAll(); diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h index 0a62584..9e8785c 100644 --- a/views/controls/button/button_dropdown.h +++ b/views/controls/button/button_dropdown.h @@ -28,7 +28,9 @@ class ButtonDropDown : public ImageButton { // Overridden from views::View 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 OnMouseReleased(const MouseEvent& event) OVERRIDE; + // Showing the drop down results in a MouseCaptureLost, we need to ignore it. + virtual void OnMouseCaptureLost() OVERRIDE {} virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; // Display the right-click menu, as triggered by the keyboard, for instance. // Using the member function ShowDropDownMenu for the actual display. diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 693e282..0cb01f6 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -131,14 +131,18 @@ bool Checkbox::OnMouseDragged(const MouseEvent& event) { return false; } -void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) { - native_wrapper_->SetPushed(false); - if (!canceled && HitTestLabel(event)) { +void Checkbox::OnMouseReleased(const MouseEvent& event) { + OnMouseCaptureLost(); + if (HitTestLabel(event)) { SetChecked(!checked()); ButtonPressed(); } } +void Checkbox::OnMouseCaptureLost() { + native_wrapper_->SetPushed(false); +} + void Checkbox::OnMouseMoved(const MouseEvent& event) { native_wrapper_->SetPushed(HitTestLabel(event)); } diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h index 19491e9..4451217 100644 --- a/views/controls/button/checkbox.h +++ b/views/controls/button/checkbox.h @@ -49,7 +49,8 @@ class Checkbox : public NativeButton { virtual std::string GetClassName() const 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 OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() 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/button/custom_button.cc b/views/controls/button/custom_button.cc index 5f8e82e..55acba8 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -129,9 +129,8 @@ bool CustomButton::OnMouseDragged(const MouseEvent& event) { return true; } -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()) +void CustomButton::OnMouseReleased(const MouseEvent& event) { + if (state_ == BS_DISABLED) return; if (!HitTest(event.location())) { @@ -140,13 +139,19 @@ void CustomButton::OnMouseReleased(const MouseEvent& event, bool canceled) { } SetState(BS_HOT); - if (!canceled && IsTriggerableEvent(event)) { + if (IsTriggerableEvent(event)) { NotifyClick(event); // NOTE: We may be deleted at this point (by the listener's notification // handler). } } +void CustomButton::OnMouseCaptureLost() { + // Starting a drag results in a MouseCaptureLost, we need to ignore it. + if (state_ != BS_DISABLED && !InDrag()) + SetState(BS_NORMAL); +} + void CustomButton::OnMouseEntered(const MouseEvent& event) { if (state_ != BS_DISABLED) SetState(BS_HOT); diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h index 8b4008c..b898483 100644 --- a/views/controls/button/custom_button.h +++ b/views/controls/button/custom_button.h @@ -80,7 +80,8 @@ class CustomButton : public Button, virtual std::string GetClassName() const 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 OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h index 7ac6a29..1b09d5f 100644 --- a/views/controls/button/image_button.h +++ b/views/controls/button/image_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. @@ -43,8 +43,8 @@ class ImageButton : public CustomButton { VerticalAlignment v_align); // Overridden from View: - virtual gfx::Size GetPreferredSize(); - virtual void OnPaint(gfx::Canvas* canvas); + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; // Sets preferred size, so it could be correctly positioned in layout even if // it is NULL. diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index 3ada964..3451434 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -198,17 +198,17 @@ bool MenuButton::OnMousePressed(const MouseEvent& event) { return true; } -void MenuButton::OnMouseReleased(const MouseEvent& event, bool canceled) { +void MenuButton::OnMouseReleased(const MouseEvent& event) { // 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(event.location()) != ui::DragDropTypes::DRAG_NONE && - state() != BS_DISABLED && !canceled && !InDrag() && - event.IsOnlyLeftMouseButton() && HitTest(event.location())) { + state() != BS_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() && + HitTest(event.location())) { Activate(); } else { - TextButton::OnMouseReleased(event, canceled); + TextButton::OnMouseReleased(event); } } diff --git a/views/controls/button/menu_button.h b/views/controls/button/menu_button.h index b564b1c..edab18b 100644 --- a/views/controls/button/menu_button.h +++ b/views/controls/button/menu_button.h @@ -55,7 +55,7 @@ class MenuButton : public TextButton { virtual gfx::Size GetPreferredSize() OVERRIDE; virtual std::string GetClassName() const OVERRIDE; virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual void OnMouseReleased(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; diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc index f162f2c..46133be 100644 --- a/views/controls/button/radio_button.cc +++ b/views/controls/button/radio_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. @@ -87,13 +87,17 @@ bool RadioButton::IsGroupFocusTraversable() const { return false; } -void RadioButton::OnMouseReleased(const MouseEvent& event, bool canceled) { - native_wrapper_->SetPushed(false); +void RadioButton::OnMouseReleased(const MouseEvent& event) { // Set the checked state to true only if we are unchecked, since we can't // be toggled on and off like a checkbox. - if (!checked() && !canceled && HitTestLabel(event)) + if (!checked() && HitTestLabel(event)) SetChecked(true); + OnMouseCaptureLost(); +} + +void RadioButton::OnMouseCaptureLost() { + native_wrapper_->SetPushed(false); ButtonPressed(); } diff --git a/views/controls/button/radio_button.h b/views/controls/button/radio_button.h index 5ff6f76..7df8387 100644 --- a/views/controls/button/radio_button.h +++ b/views/controls/button/radio_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. @@ -28,15 +28,15 @@ class RadioButton : public Checkbox { virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual View* GetSelectedViewForGroup(int group_id) OVERRIDE; virtual bool IsGroupFocusTraversable() const OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event, bool canceled) - OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; protected: // Overridden from View: virtual std::string GetClassName() const OVERRIDE; // Overridden from NativeButton: - virtual NativeButtonWrapper* CreateWrapper(); + virtual NativeButtonWrapper* CreateWrapper() OVERRIDE; private: friend class NativeRadioButtonGtk; diff --git a/views/controls/link.cc b/views/controls/link.cc index c6e22f1..0112952 100644 --- a/views/controls/link.cc +++ b/views/controls/link.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. @@ -97,38 +97,41 @@ const LinkController* Link::GetController() { return controller_; } -bool Link::OnMousePressed(const MouseEvent& e) { - if (!enabled_ || (!e.IsLeftMouseButton() && !e.IsMiddleMouseButton())) +bool Link::OnMousePressed(const MouseEvent& event) { + if (!enabled_ || (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) return false; SetHighlighted(true); return true; } -bool Link::OnMouseDragged(const MouseEvent& e) { +bool Link::OnMouseDragged(const MouseEvent& event) { SetHighlighted(enabled_ && - (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && - HitTest(e.location())); + (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && + HitTest(event.location())); return true; } -void Link::OnMouseReleased(const MouseEvent& e, bool canceled) { +void Link::OnMouseReleased(const MouseEvent& event) { // Change the highlight first just in case this instance is deleted // while calling the controller - SetHighlighted(false); - if (enabled_ && !canceled && - (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && - HitTest(e.location())) { + OnMouseCaptureLost(); + if (enabled_ && (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && + HitTest(event.location())) { // Focus the link on click. RequestFocus(); if (controller_) - controller_->LinkActivated(this, e.flags()); + controller_->LinkActivated(this, event.flags()); } } -bool Link::OnKeyPressed(const KeyEvent& e) { - bool activate = ((e.key_code() == ui::VKEY_SPACE) || - (e.key_code() == ui::VKEY_RETURN)); +void Link::OnMouseCaptureLost() { + SetHighlighted(false); +} + +bool Link::OnKeyPressed(const KeyEvent& event) { + bool activate = ((event.key_code() == ui::VKEY_SPACE) || + (event.key_code() == ui::VKEY_RETURN)); if (!activate) return false; @@ -138,15 +141,15 @@ bool Link::OnKeyPressed(const KeyEvent& e) { RequestFocus(); if (controller_) - controller_->LinkActivated(this, e.flags()); + controller_->LinkActivated(this, event.flags()); return true; } -bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) { +bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& event) { // Make sure we don't process space or enter as accelerators. - return (e.key_code() == ui::VKEY_SPACE) || - (e.key_code() == ui::VKEY_RETURN); + return (event.key_code() == ui::VKEY_SPACE) || + (event.key_code() == ui::VKEY_RETURN); } void Link::GetAccessibleState(ui::AccessibleViewState* state) { diff --git a/views/controls/link.h b/views/controls/link.h index e616317..7bdfe7a 100644 --- a/views/controls/link.h +++ b/views/controls/link.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. @@ -48,10 +48,10 @@ class Link : public Label { // Overridden from View: virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event, - bool canceled) OVERRIDE; - virtual bool OnKeyPressed(const KeyEvent& e) OVERRIDE; - virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; + virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; + virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // Overridden from Label: diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 4e9ba38..59ba744 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -377,7 +377,7 @@ void MenuController::Cancel(ExitType type) { MenuItemView* selected = state_.item; exit_type_ = type; - SendMouseReleaseToActiveView(); + SendMouseCaptureLostToActiveView(); // Hide windows immediately. SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); @@ -518,7 +518,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, // If we open a context menu just return now if (part.menu->GetDelegate()->ShowContextMenu( part.menu, part.menu->GetCommand(), loc, true)) { - SendMouseReleaseToActiveView(source, event, true); + SendMouseCaptureLostToActiveView(); return; } } @@ -530,7 +530,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, !(part.menu->HasSubmenu() && (event.flags() == ui::EF_LEFT_BUTTON_DOWN))) { if (active_mouse_view_) { - SendMouseReleaseToActiveView(source, event, false); + SendMouseReleaseToActiveView(source, event); return; } if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { @@ -542,7 +542,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); } - SendMouseReleaseToActiveView(source, event, true); + SendMouseCaptureLostToActiveView(); } void MenuController::OnMouseMoved(SubmenuView* source, @@ -1796,12 +1796,7 @@ void MenuController::UpdateActiveMouseView(SubmenuView* event_source, target = NULL; } 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. - active_mouse_view_->OnMouseReleased(event, true); - active_mouse_view_ = NULL; - } + SendMouseCaptureLostToActiveView(); active_mouse_view_ = target; if (active_mouse_view_) { gfx::Point target_point(target_menu_loc); @@ -1828,8 +1823,7 @@ void MenuController::UpdateActiveMouseView(SubmenuView* event_source, } void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, - const MouseEvent& event, - bool cancel) { + const MouseEvent& event) { if (!active_mouse_view_) return; @@ -1839,23 +1833,22 @@ void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, View::ConvertPointToView(NULL, active_mouse_view_, &target_loc); MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc.x(), target_loc.y(), event.flags()); - // Reset the active_mouse_view_ before sending mouse released. That way if if - // calls back to use we aren't in a weird state. + // Reset the active_mouse_view_ before sending mouse released. That way if it + // calls back to us, we aren't in a weird state. View* active_view = active_mouse_view_; active_mouse_view_ = NULL; - active_view->OnMouseReleased(release_event, cancel); + active_view->OnMouseReleased(release_event); } -void MenuController::SendMouseReleaseToActiveView() { +void MenuController::SendMouseCaptureLostToActiveView() { if (!active_mouse_view_) return; - MouseEvent release_event(ui::ET_MOUSE_RELEASED, -1, -1, 0); - // Reset the active_mouse_view_ before sending mouse released. That way if if - // calls back to use we aren't in a weird state. + // Reset the active_mouse_view_ before sending mouse capture lost. That way if + // it calls back to us, we aren't in a weird state. View* active_view = active_mouse_view_; active_mouse_view_ = NULL; - active_view->OnMouseReleased(release_event, true); + active_view->OnMouseCaptureLost(); } } // namespace views diff --git a/views/controls/menu/menu_controller.h b/views/controls/menu/menu_controller.h index 8458a30..177a460 100644 --- a/views/controls/menu/menu_controller.h +++ b/views/controls/menu/menu_controller.h @@ -394,11 +394,11 @@ class MenuController : public MessageLoopForUI::Dispatcher { // Sends a mouse release event to the current |active_mouse_view_| and sets // it to null. void SendMouseReleaseToActiveView(SubmenuView* event_source, - const MouseEvent& event, - bool cancel); + const MouseEvent& event); - // Variant of above that sends a cancel mouse release. - void SendMouseReleaseToActiveView(); + // Sends a mouse capture lost event to the current |active_mouse_view_| and + // sets it to null. + void SendMouseCaptureLostToActiveView(); // The active instance. static MenuController* active_instance_; diff --git a/views/controls/menu/menu_host_root_view.cc b/views/controls/menu/menu_host_root_view.cc index 0372261..dee5472 100644 --- a/views/controls/menu/menu_host_root_view.cc +++ b/views/controls/menu/menu_host_root_view.cc @@ -13,14 +13,10 @@ MenuHostRootView::MenuHostRootView(Widget* widget, SubmenuView* submenu) : RootView(widget), submenu_(submenu), - forward_drag_to_menu_controller_(true), - suspend_events_(false) { + forward_drag_to_menu_controller_(true) { } bool MenuHostRootView::OnMousePressed(const MouseEvent& event) { - if (suspend_events_) - return true; - forward_drag_to_menu_controller_ = ((event.x() < 0 || event.y() < 0 || event.x() >= width() || event.y() >= height()) || @@ -31,9 +27,6 @@ bool MenuHostRootView::OnMousePressed(const MouseEvent& event) { } bool MenuHostRootView::OnMouseDragged(const MouseEvent& event) { - if (suspend_events_) - return true; - if (forward_drag_to_menu_controller_ && GetMenuController()) { GetMenuController()->OnMouseDragged(submenu_, event); return true; @@ -41,38 +34,20 @@ bool MenuHostRootView::OnMouseDragged(const MouseEvent& event) { return RootView::OnMouseDragged(event); } -void MenuHostRootView::OnMouseReleased(const MouseEvent& event, - bool canceled) { - if (suspend_events_) - return; - - RootView::OnMouseReleased(event, canceled); +void MenuHostRootView::OnMouseReleased(const MouseEvent& event) { + RootView::OnMouseReleased(event); if (forward_drag_to_menu_controller_ && GetMenuController()) { forward_drag_to_menu_controller_ = false; - if (canceled) { - GetMenuController()->Cancel(MenuController::EXIT_ALL); - } else { - GetMenuController()->OnMouseReleased(submenu_, event); - } + GetMenuController()->OnMouseReleased(submenu_, event); } } void MenuHostRootView::OnMouseMoved(const MouseEvent& event) { - if (suspend_events_) - return; - RootView::OnMouseMoved(event); if (GetMenuController()) GetMenuController()->OnMouseMoved(submenu_, event); } -void MenuHostRootView::OnMouseExited(const MouseEvent& event) { - if (suspend_events_) - return; - - RootView::OnMouseExited(event); -} - bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) { #if defined(OS_LINUX) // ChromeOS uses MenuController to forward events like other diff --git a/views/controls/menu/menu_host_root_view.h b/views/controls/menu/menu_host_root_view.h index b8b8e34..ccd5247 100644 --- a/views/controls/menu/menu_host_root_view.h +++ b/views/controls/menu/menu_host_root_view.h @@ -23,15 +23,11 @@ class MenuHostRootView : public RootView { public: MenuHostRootView(Widget* widget, SubmenuView* submenu); - // When invoked subsequent events are NOT forwarded to the MenuController. - void suspend_events() { suspend_events_ = true; } - // Overridden from View: 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 OnMouseReleased(const MouseEvent& event) OVERRIDE; virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; private: @@ -44,10 +40,6 @@ class MenuHostRootView : public RootView { // Whether mouse dragged/released should be forwarded to the MenuController. bool forward_drag_to_menu_controller_; - // Whether events are suspended. If true, no events are forwarded to the - // MenuController. - bool suspend_events_; - DISALLOW_COPY_AND_ASSIGN(MenuHostRootView); }; diff --git a/views/controls/resize_area.cc b/views/controls/resize_area.cc index 0769cf9..c04a537 100644 --- a/views/controls/resize_area.cc +++ b/views/controls/resize_area.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. @@ -70,9 +70,12 @@ bool ResizeArea::OnMouseDragged(const views::MouseEvent& event) { return true; } -void ResizeArea::OnMouseReleased(const views::MouseEvent& event, - bool canceled) { - ReportResizeAmount(canceled ? initial_position_ : event.x(), true); +void ResizeArea::OnMouseReleased(const views::MouseEvent& event) { + ReportResizeAmount(event.x(), true); +} + +void ResizeArea::OnMouseCaptureLost() { + ReportResizeAmount(initial_position_, true); } void ResizeArea::GetAccessibleState(ui::AccessibleViewState* state) { diff --git a/views/controls/resize_area.h b/views/controls/resize_area.h index cf9bea7..6c0f66d 100644 --- a/views/controls/resize_area.h +++ b/views/controls/resize_area.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. @@ -46,8 +46,8 @@ class ResizeArea : public View { const gfx::Point& p) OVERRIDE; virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled) - OVERRIDE; + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; private: diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc index beef8c4..20a1a96 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.cc +++ b/views/controls/scrollbar/bitmap_scroll_bar.cc @@ -54,15 +54,18 @@ class AutorepeatButton : public ImageButton { virtual ~AutorepeatButton() {} protected: - virtual bool OnMousePressed(const MouseEvent& event) { + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE { Button::NotifyClick(event); repeater_.Start(); return true; } - virtual void OnMouseReleased(const MouseEvent& event, bool canceled) { + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE { + OnMouseCaptureLost(); + } + + virtual void OnMouseCaptureLost() OVERRIDE { repeater_.Stop(); - View::OnMouseReleased(event, canceled); } private: @@ -149,7 +152,7 @@ class BitmapScrollBarThumb : public View { } // View overrides: - virtual gfx::Size GetPreferredSize() { + virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(background_bitmap()->width(), start_cap_bitmap()->height() + end_cap_bitmap()->height() + @@ -158,7 +161,7 @@ class BitmapScrollBarThumb : public View { protected: // View overrides: - virtual void Paint(gfx::Canvas* canvas) { + virtual void Paint(gfx::Canvas* canvas) OVERRIDE { canvas->DrawBitmapInt(*start_cap_bitmap(), 0, 0); int top_cap_height = start_cap_bitmap()->height(); int bottom_cap_height = end_cap_bitmap()->height(); @@ -174,22 +177,22 @@ class BitmapScrollBarThumb : public View { canvas->DrawBitmapInt(*grippy_bitmap(), grippy_x, grippy_y); } - virtual void OnMouseEntered(const MouseEvent& event) { + virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE { SetState(CustomButton::BS_HOT); } - virtual void OnMouseExited(const MouseEvent& event) { + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE { SetState(CustomButton::BS_NORMAL); } - virtual bool OnMousePressed(const MouseEvent& event) { + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE { mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y(); drag_start_position_ = GetPosition(); SetState(CustomButton::BS_PUSHED); return true; } - virtual bool OnMouseDragged(const MouseEvent& event) { + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE { // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside // the bounds of the thumb, the scrollbar will snap the scroll back to the // point it was at before the drag began. @@ -216,10 +219,12 @@ class BitmapScrollBarThumb : public View { return true; } - virtual void OnMouseReleased(const MouseEvent& event, - bool canceled) { + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE { + OnMouseCaptureLost(); + } + + virtual void OnMouseCaptureLost() OVERRIDE { SetState(CustomButton::BS_HOT); - View::OnMouseReleased(event, canceled); } private: @@ -471,10 +476,13 @@ bool BitmapScrollBar::OnMousePressed(const MouseEvent& event) { return true; } -void BitmapScrollBar::OnMouseReleased(const MouseEvent& event, bool canceled) { +void BitmapScrollBar::OnMouseReleased(const MouseEvent& event) { + OnMouseCaptureLost(); +} + +void BitmapScrollBar::OnMouseCaptureLost() { SetThumbTrackState(CustomButton::BS_NORMAL); repeater_.Stop(); - View::OnMouseReleased(event, canceled); } bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) { diff --git a/views/controls/scrollbar/bitmap_scroll_bar.h b/views/controls/scrollbar/bitmap_scroll_bar.h index 8357fd1..833a045 100644 --- a/views/controls/scrollbar/bitmap_scroll_bar.h +++ b/views/controls/scrollbar/bitmap_scroll_bar.h @@ -98,7 +98,8 @@ class BitmapScrollBar : public ScrollBar, virtual gfx::Size GetPreferredSize() OVERRIDE; virtual void Layout() OVERRIDE; virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index 76e924e..d9f8912 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.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. @@ -182,11 +182,11 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { return true; } -void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) { +void SingleSplitView::OnMouseCaptureLost() { if (child_count() < 2) return; - if (canceled && drag_info_.initial_divider_offset != divider_offset_) { + if (drag_info_.initial_divider_offset != divider_offset_) { set_divider_offset(drag_info_.initial_divider_offset); if (!observer_ || observer_->SplitHandleMoved(this)) Layout(); diff --git a/views/controls/single_split_view.h b/views/controls/single_split_view.h index de4ccf5..63fd702 100644 --- a/views/controls/single_split_view.h +++ b/views/controls/single_split_view.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. @@ -80,7 +80,7 @@ class SingleSplitView : public views::View { // View overrides. 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 OnMouseCaptureLost() OVERRIDE; virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; private: diff --git a/views/controls/single_split_view_unittest.cc b/views/controls/single_split_view_unittest.cc index 65fbb00..f880528 100644 --- a/views/controls/single_split_view_unittest.cc +++ b/views/controls/single_split_view_unittest.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. @@ -133,9 +133,9 @@ TEST(SingleSplitViewTest, MouseDrag) { ON_CALL(observer, SplitHandleMoved(_)) .WillByDefault(Return(true)); - // SplitHandleMoved is expected to be called once for every mouse move. + // SplitHandleMoved is called for two mouse moves and one mouse capture loss. EXPECT_CALL(observer, SplitHandleMoved(_)) - .Times(2); + .Times(3); split.SetBounds(0, 0, 10, 100); const int kInitialDividerOffset = 33; @@ -166,9 +166,14 @@ TEST(SingleSplitViewTest, MouseDrag) { MouseEvent mouse_released( ui::ET_MOUSE_RELEASED, 7, kInitialDividerOffset + kMouseOffset + kMouseMoveDelta * 2, 0); - split.OnMouseReleased(mouse_released, false); + split.OnMouseReleased(mouse_released); EXPECT_EQ(kInitialDividerOffset + kMouseMoveDelta * 2, split.divider_offset()); + + // Expect intial offset after a system/user gesture cancels the drag. + // This shouldn't occur after mouse release, but it's sufficient for testing. + split.OnMouseCaptureLost(); + EXPECT_EQ(kInitialDividerOffset, split.divider_offset()); } } // namespace views diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc index 48bdea9..e1b8ccc 100644 --- a/views/controls/textfield/native_textfield_views.cc +++ b/views/controls/textfield/native_textfield_views.cc @@ -85,17 +85,17 @@ NativeTextfieldViews::~NativeTextfieldViews() { //////////////////////////////////////////////////////////////////////////////// // NativeTextfieldViews, View overrides: -bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) { +bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& event) { OnBeforeUserAction(); - if (HandleMousePressed(e)) + if (HandleMousePressed(event)) SchedulePaint(); OnAfterUserAction(); return true; } -bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& e) { +bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& event) { OnBeforeUserAction(); - size_t pos = FindCursorPosition(e.location()); + size_t pos = FindCursorPosition(event.location()); if (model_->MoveCursorTo(pos, true)) { UpdateCursorBoundsAndTextOffset(); SchedulePaint(); @@ -104,18 +104,14 @@ bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& e) { return true; } -void NativeTextfieldViews::OnMouseReleased(const views::MouseEvent& e, - bool canceled) { -} - -bool NativeTextfieldViews::OnKeyPressed(const views::KeyEvent& e) { +bool NativeTextfieldViews::OnKeyPressed(const views::KeyEvent& event) { // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on // NativeTextfieldViews as it will never gain focus. NOTREACHED(); return false; } -bool NativeTextfieldViews::OnKeyReleased(const views::KeyEvent& e) { +bool NativeTextfieldViews::OnKeyReleased(const views::KeyEvent& event) { NOTREACHED(); return false; } @@ -470,7 +466,7 @@ void NativeTextfieldViews::UpdateCursorBoundsAndTextOffset() { } else if (x_left < 0) { // when the cursor overflows to the left text_offset_ = -cursor_bounds_.x(); - } else if(full_width > width && text_offset_ + full_width < width) { + } else if (full_width > width && text_offset_ + full_width < width) { // when the cursor moves within the textfield with the text // longer than the field. text_offset_ = width - full_width; diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h index 7cc8317f..c91281b 100644 --- a/views/controls/textfield/native_textfield_views.h +++ b/views/controls/textfield/native_textfield_views.h @@ -47,12 +47,10 @@ class NativeTextfieldViews : public views::View, ~NativeTextfieldViews(); // views::View overrides: - virtual bool OnMousePressed(const views::MouseEvent& e) OVERRIDE; - virtual bool OnMouseDragged(const views::MouseEvent& e) OVERRIDE; - virtual void OnMouseReleased(const views::MouseEvent& e, - bool canceled) OVERRIDE; - virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; - virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; + virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; + virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; |