diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 09:28:48 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 09:28:48 +0000 |
commit | 4176215f7cf7c88be763a488f68283da34fce463 (patch) | |
tree | 26261df92334a51fe01fdfaf04135ee913103bcd /chrome/browser | |
parent | e9577101dce15bbd4fd92b517c845230cdc57d5d (diff) | |
download | chromium_src-4176215f7cf7c88be763a488f68283da34fce463.zip chromium_src-4176215f7cf7c88be763a488f68283da34fce463.tar.gz chromium_src-4176215f7cf7c88be763a488f68283da34fce463.tar.bz2 |
Revert 125319 - Change panel drag related methods to use mouse location in screen coordinates.
This is in preparation for support inter-strip dragging.
BUG=none
TEST=existing tests due to no functionality change
Review URL: http://codereview.chromium.org/9616037
TBR=jianli@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9639007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
18 files changed, 135 insertions, 244 deletions
diff --git a/chrome/browser/ui/panels/detached_panel_browsertest.cc b/chrome/browser/ui/panels/detached_panel_browsertest.cc index 885cc1d..24e22c1 100644 --- a/chrome/browser/ui/panels/detached_panel_browsertest.cc +++ b/chrome/browser/ui/panels/detached_panel_browsertest.cc @@ -55,12 +55,12 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DragDetachedPanel) { panel_testing->PressLeftMouseButtonTitlebar(origin); EXPECT_EQ(origin, panel->GetBounds().origin()); - origin.Offset(-51, -102); - panel_testing->DragTitlebar(origin); + panel_testing->DragTitlebar(-51, 102); + origin.Offset(-51, 102); EXPECT_EQ(origin, panel->GetBounds().origin()); - origin.Offset(37, 45); - panel_testing->DragTitlebar(origin); + panel_testing->DragTitlebar(37, -42); + origin.Offset(37, -42); EXPECT_EQ(origin, panel->GetBounds().origin()); panel_testing->FinishDragTitlebar(); @@ -74,13 +74,12 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DragDetachedPanel) { panel_testing->PressLeftMouseButtonTitlebar(origin); EXPECT_EQ(origin, panel->GetBounds().origin()); - origin.Offset(-51, -102); - panel_testing->DragTitlebar(origin); - + panel_testing->DragTitlebar(-51, 102); + origin.Offset(-51, 102); EXPECT_EQ(origin, panel->GetBounds().origin()); - origin.Offset(37, 45); - panel_testing->DragTitlebar(origin); + panel_testing->DragTitlebar(37, -42); + origin.Offset(37, -42); EXPECT_EQ(origin, panel->GetBounds().origin()); panel_testing->CancelDragTitlebar(); @@ -119,7 +118,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) { // Start dragging a panel. panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); - panel1_testing->DragTitlebar(panel1_new_position); + panel1_testing->DragTitlebar(-51, -102); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -167,7 +166,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) { // Start dragging a panel. panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); - panel1_testing->DragTitlebar(panel1_new_position); + panel1_testing->DragTitlebar(-51, -102); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -209,7 +208,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) { // Start dragging a panel again. panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); - panel1_testing->DragTitlebar(panel1_new_position); + panel1_testing->DragTitlebar(-51, -102); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); diff --git a/chrome/browser/ui/panels/native_panel.h b/chrome/browser/ui/panels/native_panel.h index a2eb4e0..2298b77 100644 --- a/chrome/browser/ui/panels/native_panel.h +++ b/chrome/browser/ui/panels/native_panel.h @@ -96,11 +96,9 @@ class NativePanelTesting { static NativePanelTesting* Create(NativePanel* native_panel); virtual ~NativePanelTesting() {} - // |mouse_location| is in screen coordinates. - virtual void PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) = 0; + virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) = 0; virtual void ReleaseMouseButtonTitlebar() = 0; - virtual void DragTitlebar(const gfx::Point& mouse_location) = 0; + virtual void DragTitlebar(int delta_x, int delta_y) = 0; virtual void CancelDragTitlebar() = 0; virtual void FinishDragTitlebar() = 0; diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc index f932c64..e5c7c50 100644 --- a/chrome/browser/ui/panels/panel_browser_frame_view.cc +++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc @@ -594,25 +594,15 @@ void PanelBrowserFrameView::GetAccessibleState(ui::AccessibleViewState* state) { } bool PanelBrowserFrameView::OnMousePressed(const views::MouseEvent& event) { - // |event.location| is in the view's coordinate system. Convert it to the - // screen coordinate system. - gfx::Point mouse_location = event.location(); - views::View::ConvertPointToScreen(this, &mouse_location); - if (event.IsOnlyLeftMouseButton() && - panel_browser_view_->OnTitlebarMousePressed(mouse_location)) { + panel_browser_view_->OnTitlebarMousePressed(event.location())) { return true; } return BrowserNonClientFrameView::OnMousePressed(event); } bool PanelBrowserFrameView::OnMouseDragged(const views::MouseEvent& event) { - // |event.location| is in the view's coordinate system. Convert it to the - // screen coordinate system. - gfx::Point mouse_location = event.location(); - views::View::ConvertPointToScreen(this, &mouse_location); - - if (panel_browser_view_->OnTitlebarMouseDragged(mouse_location)) + if (panel_browser_view_->OnTitlebarMouseDragged(event.location())) return true; return BrowserNonClientFrameView::OnMouseDragged(event); } diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc index 92daaa3..9873a24 100644 --- a/chrome/browser/ui/panels/panel_browser_view.cc +++ b/chrome/browser/ui/panels/panel_browser_view.cc @@ -427,17 +427,19 @@ PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); } -bool PanelBrowserView::OnTitlebarMousePressed( - const gfx::Point& mouse_location) { +bool PanelBrowserView::OnTitlebarMousePressed(const gfx::Point& location) { + // |location| is in the view's coordinate system. Convert it to the screen + // coordinate system. + mouse_location_ = location; + views::View::ConvertPointToScreen(this, &mouse_location_); + mouse_pressed_ = true; mouse_pressed_time_ = base::TimeTicks::Now(); mouse_dragging_state_ = NO_DRAGGING; - mouse_location_ = mouse_location; return true; } -bool PanelBrowserView::OnTitlebarMouseDragged( - const gfx::Point& mouse_location) { +bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { if (!mouse_pressed_) return false; @@ -445,7 +447,11 @@ bool PanelBrowserView::OnTitlebarMouseDragged( return true; gfx::Point last_mouse_location = mouse_location_; - mouse_location_ = mouse_location; + + // |location| is in the view's coordinate system. Convert it to the screen + // coordinate system. + mouse_location_ = location; + views::View::ConvertPointToScreen(this, &mouse_location_); int delta_x = mouse_location_.x() - last_mouse_location.x(); int delta_y = mouse_location_.y() - last_mouse_location.y(); @@ -456,11 +462,11 @@ bool PanelBrowserView::OnTitlebarMouseDragged( old_focused_view_ = GetFocusManager()->GetFocusedView(); GetFocusManager()->SetFocusedView(GetFrameView()); - panel_->manager()->StartDragging(panel_.get(), last_mouse_location); + panel_->manager()->StartDragging(panel_.get()); mouse_dragging_state_ = DRAGGING_STARTED; } if (mouse_dragging_state_ == DRAGGING_STARTED) - panel_->manager()->Drag(mouse_location_); + panel_->manager()->Drag(delta_x, delta_y); return true; } @@ -544,9 +550,9 @@ class NativePanelTestingWin : public NativePanelTesting { private: virtual void PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) OVERRIDE; + const gfx::Point& point) OVERRIDE; virtual void ReleaseMouseButtonTitlebar() OVERRIDE; - virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; + virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; virtual void CancelDragTitlebar() OVERRIDE; virtual void FinishDragTitlebar() OVERRIDE; virtual bool VerifyDrawingAttention() const OVERRIDE; @@ -571,16 +577,23 @@ NativePanelTestingWin::NativePanelTestingWin( } void NativePanelTestingWin::PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) { - panel_browser_view_->OnTitlebarMousePressed(mouse_location); + const gfx::Point& point) { + panel_browser_view_->OnTitlebarMousePressed(point); } void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { panel_browser_view_->OnTitlebarMouseReleased(); } -void NativePanelTestingWin::DragTitlebar(const gfx::Point& mouse_location) { - panel_browser_view_->OnTitlebarMouseDragged(mouse_location); +void NativePanelTestingWin::DragTitlebar(int delta_x, int delta_y) { + gfx::Point new_mouse_location = panel_browser_view_->mouse_location_; + new_mouse_location.Offset(delta_x, delta_y); + + // Convert from the screen coordinate system to the view's coordinate system + // since OnTitlebarMouseDragged takes the point in the latter. + views::View::ConvertPointToView(NULL, panel_browser_view_, + &new_mouse_location); + panel_browser_view_->OnTitlebarMouseDragged(new_mouse_location); } void NativePanelTestingWin::CancelDragTitlebar() { diff --git a/chrome/browser/ui/panels/panel_browser_view.h b/chrome/browser/ui/panels/panel_browser_view.h index e6e8dee..00798fb 100644 --- a/chrome/browser/ui/panels/panel_browser_view.h +++ b/chrome/browser/ui/panels/panel_browser_view.h @@ -38,9 +38,8 @@ class PanelBrowserView : public BrowserView, // Called from frame view when titlebar receives a mouse event. // Return true if the event is handled. - // |mouse_location| is in screen coordinates. - bool OnTitlebarMousePressed(const gfx::Point& mouse_location); - bool OnTitlebarMouseDragged(const gfx::Point& mouse_location); + bool OnTitlebarMousePressed(const gfx::Point& location); + bool OnTitlebarMouseDragged(const gfx::Point& location); bool OnTitlebarMouseReleased(); bool OnTitlebarMouseCaptureLost(); diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm index ff041d3..5f5a068 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm @@ -13,7 +13,6 @@ #include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel_manager.h" #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" -#import "chrome/browser/ui/panels/panel_utils_cocoa.h" #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/public/browser/native_web_keyboard_event.h" @@ -27,6 +26,19 @@ namespace { // (according to avi@). const int kMinimumWindowSize = 1; +// TODO(dcheng): Move elsewhere so BrowserWindowCocoa can use them too. +// Converts global screen coordinates in platfrom-independent coordinates +// (with the (0,0) in the top-left corner of the primary screen) to the Cocoa +// screen coordinates (with (0,0) in the low-left corner). +NSRect ConvertCoordinatesToCocoa(const gfx::Rect& bounds) { + // Flip coordinates based on the primary screen. + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; + + return NSMakeRect( + bounds.x(), NSHeight([screen frame]) - bounds.height() - bounds.y(), + bounds.width(), bounds.height()); +} + } // namespace // This creates a shim window class, which in turn creates a Cocoa window @@ -85,7 +97,7 @@ void PanelBrowserWindowCocoa::ShowPanelInactive() { SetPanelBoundsInstantly(bounds_); is_shown_ = true; - NSRect finalFrame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds_); + NSRect finalFrame = ConvertCoordinatesToCocoa(bounds_); [controller_ revealAnimatedWithFrame:finalFrame]; } @@ -112,7 +124,7 @@ void PanelBrowserWindowCocoa::setBoundsInternal(const gfx::Rect& bounds, bounds_ = bounds; - NSRect frame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds); + NSRect frame = ConvertCoordinatesToCocoa(bounds); [controller_ setPanelFrame:frame animate:animate]; } @@ -303,10 +315,9 @@ class NativePanelTestingCocoa : public NativePanelTesting { NativePanelTestingCocoa(NativePanel* native_panel); virtual ~NativePanelTestingCocoa() { } // Overridden from NativePanelTesting - virtual void PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) OVERRIDE; + virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) OVERRIDE; virtual void ReleaseMouseButtonTitlebar() OVERRIDE; - virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; + virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; virtual void CancelDragTitlebar() OVERRIDE; virtual void FinishDragTitlebar() OVERRIDE; virtual bool VerifyDrawingAttention() const OVERRIDE; @@ -334,24 +345,16 @@ PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const { } void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) { - // Convert from platform-indepedent screen coordinates to Cocoa's screen - // coordinates because PanelTitlebarViewCocoa method takes Cocoa's screen - // coordinates. - [titlebar() pressLeftMouseButtonTitlebar: - cocoa_utils::ConvertPointToCocoaCoordinates(mouse_location)]; + const gfx::Point& point) { + [titlebar() pressLeftMouseButtonTitlebar]; } void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() { [titlebar() releaseLeftMouseButtonTitlebar]; } -void NativePanelTestingCocoa::DragTitlebar(const gfx::Point& mouse_location) { - // Convert from platform-indepedent screen coordinates to Cocoa's screen - // coordinates because PanelTitlebarViewCocoa method takes Cocoa's screen - // coordinates. - [titlebar() dragTitlebar: - cocoa_utils::ConvertPointToCocoaCoordinates(mouse_location)]; +void NativePanelTestingCocoa::DragTitlebar(int delta_x, int delta_y) { + [titlebar() dragTitlebarDeltaX:delta_x deltaY:delta_y]; } void NativePanelTestingCocoa::CancelDragTitlebar() { diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc index 8be2f47..f84b84f 100644 --- a/chrome/browser/ui/panels/panel_browser_window_gtk.cc +++ b/chrome/browser/ui/panels/panel_browser_window_gtk.cc @@ -551,11 +551,11 @@ void PanelBrowserWindowGtk::DidProcessEvent(GdkEvent* event) { // it here to reduce the reference count. gtk_target_list_unref(list); } - panel_->manager()->StartDragging(panel_.get(), gfx::Point(old_x, old_y)); + panel_->manager()->StartDragging(panel_.get()); } if (drag_widget_) { - panel_->manager()->Drag(gfx::Point(new_x, new_y)); + panel_->manager()->Drag(new_x - old_x, new_y - old_y); gdk_event_free(last_mouse_down_); last_mouse_down_ = gdk_event_copy(event); } @@ -777,9 +777,9 @@ class NativePanelTestingGtk : public NativePanelTesting { private: virtual void PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) OVERRIDE; + const gfx::Point& point) OVERRIDE; virtual void ReleaseMouseButtonTitlebar() OVERRIDE; - virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE; + virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; virtual void CancelDragTitlebar() OVERRIDE; virtual void FinishDragTitlebar() OVERRIDE; virtual bool VerifyDrawingAttention() const OVERRIDE; @@ -803,7 +803,7 @@ NativePanelTestingGtk::NativePanelTestingGtk( } void NativePanelTestingGtk::PressLeftMouseButtonTitlebar( - const gfx::Point& mouse_location) { + const gfx::Point& point) { // If there is an animation, wait for it to finish as we don't handle button // clicks while animation is in progress. while (panel_browser_window_gtk_->IsAnimatingBounds()) @@ -811,8 +811,8 @@ void NativePanelTestingGtk::PressLeftMouseButtonTitlebar( GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); event->button.button = 1; - event->button.x_root = mouse_location.x(); - event->button.y_root = mouse_location.y(); + event->button.x_root = point.x(); + event->button.y_root = point.y(); panel_browser_window_gtk_->OnTitlebarButtonPressEvent( panel_browser_window_gtk_->titlebar_widget(), reinterpret_cast<GdkEventButton*>(event)); @@ -829,13 +829,15 @@ void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() { MessageLoopForUI::current()->RunAllPending(); } -void NativePanelTestingGtk::DragTitlebar(const gfx::Point& mouse_location) { +void NativePanelTestingGtk::DragTitlebar(int delta_x, int delta_y) { // Prevent extra unwanted signals and focus grabs. panel_browser_window_gtk_->system_drag_disabled_for_testing_ = true; GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); - event->motion.x_root = mouse_location.x(); - event->motion.y_root = mouse_location.y(); + gdk_event_get_root_coords(panel_browser_window_gtk_->last_mouse_down_, + &event->motion.x_root, &event->motion.y_root); + event->motion.x_root += delta_x; + event->motion.y_root += delta_y; panel_browser_window_gtk_->DidProcessEvent(event); gdk_event_free(event); MessageLoopForUI::current()->RunAllPending(); diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index 5b2d34e..c0cd60f 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -178,15 +178,13 @@ class PanelBrowserTest : public BasePanelBrowserTest { if (drag_action & DRAG_ACTION_BEGIN) { // Trigger the mouse-pressed event. // All panels should remain in their original positions. - test_dragging_mouse_location_ = panels[drag_index]->GetBounds().origin(); panel_testing_to_drag->PressLeftMouseButtonTitlebar( - test_dragging_mouse_location_); + panels[drag_index]->GetBounds().origin()); EXPECT_EQ(test_begin_bounds, GetPanelBounds(panels)); } // Trigger the drag. - test_dragging_mouse_location_.Offset(delta_x, delta_y); - panel_testing_to_drag->DragTitlebar(test_dragging_mouse_location_); + panel_testing_to_drag->DragTitlebar(delta_x, delta_y); // Compare against expected bounds. EXPECT_EQ(AddXDeltaToBounds(test_begin_bounds, expected_delta_x_after_drag), @@ -407,12 +405,6 @@ class PanelBrowserTest : public BasePanelBrowserTest { for (size_t i = 0; i < panels.size(); ++i) delete native_panels_testing[i]; } - - private: - // TODO(jianli): This is a temporary workaround to make TestDragging work - // with mouse location parameter changes. Fix this when we move drag related - // tests to new testing class. - gfx::Point test_dragging_mouse_location_; }; IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { @@ -787,11 +779,9 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) { scoped_ptr<NativePanelTesting> panel_testing( NativePanelTesting::Create(panel->native_panel())); gfx::Rect bounds = panel->GetBounds(); - gfx::Point mouse_location = bounds.origin(); - panel_testing->PressLeftMouseButtonTitlebar(mouse_location); + panel_testing->PressLeftMouseButtonTitlebar(bounds.origin()); EXPECT_EQ(bounds.x(), panel->GetBounds().x()); - mouse_location.Offset(-50, 10); - panel_testing->DragTitlebar(mouse_location); + panel_testing->DragTitlebar(-50, 10); EXPECT_EQ(bounds.x(), panel->GetBounds().x()); panel_testing->FinishDragTitlebar(); EXPECT_EQ(bounds.x(), panel->GetBounds().x()); @@ -807,7 +797,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { PanelDragController* drag_controller = panel_manager->drag_controller(); DockedPanelStrip* docked_strip = panel_manager->docked_strip(); - // Create 4 docked panels. + // Create 4 detached panels. // We have: P4 P3 P2 P1 Panel* panel1 = CreatePanelWithBounds("Panel1", gfx::Rect(0, 0, 100, 100)); Panel* panel2 = CreatePanelWithBounds("Panel2", gfx::Rect(0, 0, 100, 100)); @@ -830,10 +820,8 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { // Start dragging a panel. // We have: P1* P4 P3 P2 - gfx::Point mouse_location = panel1->GetBounds().origin(); - panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); - mouse_location.Offset(-500, -5); - panel1_testing->DragTitlebar(mouse_location); + panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); + panel1_testing->DragTitlebar(-500, -5); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -887,10 +875,8 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { // Start dragging a panel. // We have: P1* P4 P3 - gfx::Point mouse_location = panel1->GetBounds().origin(); - panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); - mouse_location.Offset(-500, -5); - panel1_testing->DragTitlebar(mouse_location); + panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); + panel1_testing->DragTitlebar(-500, -5); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -938,10 +924,8 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) { // Start dragging a panel again. // We have: P1* P4 - gfx::Point mouse_location = panel1->GetBounds().origin(); - panel1_testing->PressLeftMouseButtonTitlebar(mouse_location); - mouse_location.Offset(-500, -5); - panel1_testing->DragTitlebar(mouse_location); + panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin()); + panel1_testing->DragTitlebar(-500, -5); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); diff --git a/chrome/browser/ui/panels/panel_drag_controller.cc b/chrome/browser/ui/panels/panel_drag_controller.cc index 7cd0990..2a21cd28 100644 --- a/chrome/browser/ui/panels/panel_drag_controller.cc +++ b/chrome/browser/ui/panels/panel_drag_controller.cc @@ -15,28 +15,20 @@ PanelDragController::PanelDragController() PanelDragController::~PanelDragController() { } -void PanelDragController::StartDragging(Panel* panel, - const gfx::Point& mouse_location) { +void PanelDragController::StartDragging(Panel* panel) { DCHECK(!dragging_panel_); DCHECK(panel->draggable()); - last_mouse_location_ = mouse_location; - dragging_panel_ = panel; dragging_panel_original_position_ = panel->GetBounds().origin(); dragging_panel_->panel_strip()->StartDraggingPanel(panel); } -void PanelDragController::Drag(const gfx::Point& mouse_location) { +void PanelDragController::Drag(int delta_x, int delta_y) { DCHECK(dragging_panel_); - dragging_panel_->panel_strip()->DragPanel( - dragging_panel_, - mouse_location.x() - last_mouse_location_.x(), - mouse_location.y() - last_mouse_location_.y()); - - last_mouse_location_ = mouse_location; + dragging_panel_->panel_strip()->DragPanel(dragging_panel_, delta_x, delta_y); } void PanelDragController::EndDragging(bool cancelled) { diff --git a/chrome/browser/ui/panels/panel_drag_controller.h b/chrome/browser/ui/panels/panel_drag_controller.h index df944a5..a58b764 100644 --- a/chrome/browser/ui/panels/panel_drag_controller.h +++ b/chrome/browser/ui/panels/panel_drag_controller.h @@ -19,10 +19,8 @@ class PanelDragController { PanelDragController(); ~PanelDragController(); - // Drags the given panel. - // |mouse_location| is in screen coordinate system. - void StartDragging(Panel* panel, const gfx::Point& mouse_location); - void Drag(const gfx::Point& mouse_location); + void StartDragging(Panel* panel); + void Drag(int delta_x, int delta_y); void EndDragging(bool cancelled); // Asynchronous confirmation of panel having been closed. @@ -44,10 +42,6 @@ class PanelDragController { // dragging. gfx::Point dragging_panel_original_position_; - // The mouse location, in screen coordinates, when StartDragging or Drag was - // pveviously called. - gfx::Point last_mouse_location_; - DISALLOW_COPY_AND_ASSIGN(PanelDragController); }; diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc index 70c9f41..8b06ce7 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -155,13 +155,12 @@ void PanelManager::OnPanelClosed(Panel* panel) { content::NotificationService::NoDetails()); } -void PanelManager::StartDragging(Panel* panel, - const gfx::Point& mouse_location) { - drag_controller_->StartDragging(panel, mouse_location); +void PanelManager::StartDragging(Panel* panel) { + drag_controller_->StartDragging(panel); } -void PanelManager::Drag(const gfx::Point& mouse_location) { - drag_controller_->Drag(mouse_location); +void PanelManager::Drag(int delta_x, int delta_y) { + drag_controller_->Drag(delta_x, delta_y); } void PanelManager::EndDragging(bool cancelled) { diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h index 563903c..7f72726 100644 --- a/chrome/browser/ui/panels/panel_manager.h +++ b/chrome/browser/ui/panels/panel_manager.h @@ -46,9 +46,8 @@ class PanelManager : public DisplaySettingsProvider::Observer { void OnPanelClosed(Panel* panel); // Drags the given panel. - // |mouse_location| is in screen coordinate system. - void StartDragging(Panel* panel, const gfx::Point& mouse_location); - void Drag(const gfx::Point& mouse_location); + void StartDragging(Panel* panel); + void Drag(int delta_x, int delta_y); void EndDragging(bool cancelled); // Invoked when a panel's expansion state changes. diff --git a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.h b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.h index e6f83bf..a93f5b8 100644 --- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.h +++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.h @@ -58,7 +58,7 @@ enum PanelDragState { ScopedCrTrackingArea closeButtonTrackingArea_; PanelDragState dragState_; BOOL isDrawingAttention_; - NSPoint dragStartLocation_; // in cocoa's screen coordinates. + NSPoint dragStartLocation_; // "Glint" animation is used in "Draw Attention" mode. scoped_nsobject<RepaintAnimation> glintAnimation_; scoped_nsobject<NSTimer> glintAnimationTimer_; @@ -89,10 +89,10 @@ enum PanelDragState { - (void)didChangeMainWindow:(NSNotification*)notification; // Helpers to control title drag operation, called from more then one place. -// |mouseLocation| is in Cocoa's screen coordinates. -- (void)startDrag:(NSPoint)mouseLocation; +- (void)startDrag; - (void)endDrag:(BOOL)cancelled; -- (void)drag:(NSPoint)mouseLocation; +- (void)dragWithDeltaX:(int)deltaX + deltaY:(int)deltaY; // Update the visibility of settings button. - (void)updateSettingsButtonVisibility:(BOOL)mouseOverWindow; @@ -122,10 +122,10 @@ enum PanelDragState { - (void)simulateCloseButtonClick; // NativePanelTesting support. -// |mouseLocation| is in Cocoa's screen coordinates. -- (void)pressLeftMouseButtonTitlebar:(NSPoint)mouseLocation; +- (void)pressLeftMouseButtonTitlebar; - (void)releaseLeftMouseButtonTitlebar; -- (void)dragTitlebar:(NSPoint)mouseLocation; +- (void)dragTitlebarDeltaX:(double)delta_x + deltaY:(double)delta_y; - (void)cancelDragTitlebar; - (void)finishDragTitlebar; diff --git a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm index 6b1ba0f..f637494 100644 --- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm +++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm @@ -392,8 +392,7 @@ static NSEvent* MakeMouseEvent(NSEventType type, - (void)mouseDown:(NSEvent*)event { if ([controller_ isDraggable]) { dragState_ = PANEL_DRAG_CAN_START; - dragStartLocation_ = - [[self window] convertBaseToScreen:[event locationInWindow]]; + dragStartLocation_ = [event locationInWindow]; } } @@ -405,8 +404,8 @@ static NSEvent* MakeMouseEvent(NSEventType type, } - (BOOL)exceedsDragThreshold:(NSPoint)mouseLocation { - float deltaX = fabs(dragStartLocation_.x - mouseLocation.x); - float deltaY = fabs(dragStartLocation_.y - mouseLocation.y); + float deltaX = dragStartLocation_.x - mouseLocation.x; + float deltaY = dragStartLocation_.y - mouseLocation.y; return deltaX > kDragThreshold || deltaY > kDragThreshold; } @@ -431,19 +430,15 @@ static NSEvent* MakeMouseEvent(NSEventType type, dequeue:YES]; switch ([event type]) { - case NSLeftMouseDragged: { - // Get current mouse location in Cocoa's screen coordinates. - NSPoint mouseLocation = - [[self window] convertBaseToScreen:[event locationInWindow]]; + case NSLeftMouseDragged: if (dragState_ == PANEL_DRAG_CAN_START) { - if (![self exceedsDragThreshold:mouseLocation]) + if (![self exceedsDragThreshold:[event locationInWindow]]) return; // Don't start real drag yet. - [self startDrag:dragStartLocation_]; + [self startDrag]; } - DCHECK(dragState_ == PANEL_DRAG_IN_PROGRESS); - [self drag:mouseLocation]; + [self dragWithDeltaX:[event deltaX] + deltaY:[event deltaY]]; break; - } case NSKeyUp: if ([event keyCode] == kVK_Escape) { @@ -473,10 +468,10 @@ static NSEvent* MakeMouseEvent(NSEventType type, } } -- (void)startDrag:(NSPoint)mouseLocation { +- (void)startDrag { DCHECK(dragState_ == PANEL_DRAG_CAN_START); dragState_ = PANEL_DRAG_IN_PROGRESS; - [controller_ startDrag:mouseLocation]; + [controller_ startDrag]; } - (void)endDrag:(BOOL)cancelled { @@ -485,10 +480,12 @@ static NSEvent* MakeMouseEvent(NSEventType type, dragState_ = PANEL_DRAG_SUPPRESSED; } -- (void)drag:(NSPoint)mouseLocation { +- (void)dragWithDeltaX:(int)deltaX + deltaY:(int)deltaY { if (dragState_ != PANEL_DRAG_IN_PROGRESS) return; - [controller_ drag:mouseLocation]; + [controller_ dragWithDeltaX:deltaX + deltaY:deltaY]; } - (void)drawAttention { @@ -572,11 +569,8 @@ static NSEvent* MakeMouseEvent(NSEventType type, [[closeButton_ cell] performClick:closeButton_]; } -- (void)pressLeftMouseButtonTitlebar:(NSPoint)mouseLocation { - // Convert from Cocoa's screen coordinates to base coordinates since the mouse - // event takes base coordinates. - NSEvent* event = MakeMouseEvent( - NSLeftMouseDown, [[self window] convertScreenToBase:mouseLocation], 0); +- (void)pressLeftMouseButtonTitlebar { + NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0); [self mouseDown:event]; } @@ -585,12 +579,12 @@ static NSEvent* MakeMouseEvent(NSEventType type, [self mouseUp:event]; } -- (void)dragTitlebar:(NSPoint)mouseLocation { +- (void)dragTitlebarDeltaX:(double)delta_x + deltaY:(double)delta_y { if (dragState_ == PANEL_DRAG_CAN_START) - [self startDrag:dragStartLocation_]; - // No need to do any conversion since |mouseLocation| is already in Cocoa's - // screen coordinates. - [self drag:mouseLocation]; + [self startDrag]; + [self dragWithDeltaX:delta_x + deltaY:delta_y]; } - (void)cancelDragTitlebar { diff --git a/chrome/browser/ui/panels/panel_utils_cocoa.h b/chrome/browser/ui/panels/panel_utils_cocoa.h deleted file mode 100644 index 47a186b..0000000 --- a/chrome/browser/ui/panels/panel_utils_cocoa.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_UI_PANELS_PANEL_UTILS_COCOA_H_ -#define CHROME_BROWSER_UI_PANELS_PANEL_UTILS_COCOA_H_ -#pragma once - -#import <Cocoa/Cocoa.h> -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" - -namespace cocoa_utils { - -// TODO(dcheng): Move elsewhere so BrowserWindowCocoa can use them too. -// Converts a rect from the platfrom-independent screen coordinates (with the -// (0,0) in the top-left corner of the primary screen) to the Cocoa screen -// coordinates (with (0,0) in the low-left corner). -NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds); - -// Converts a point from the platfrom-independent screen coordinates (with the -// (0,0) in the top-left corner of the primary screen) to the Cocoa screen -// coordinates (with (0,0) in the low-left corner). -NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point); - -// Converts a point from the Cocoa screen coordinates (with (0,0) in the -// low-left corner of the primary screen) to the platfrom-independent screen -// coordinates (with the (0,0) in the top-left corner). -gfx::Point ConvertPointFromCocoaCoordinates(NSPoint point); - -} // namespace cocoa_utils - -#endif // CHROME_BROWSER_UI_PANELS_PANEL_UTILS_COCOA_H_ diff --git a/chrome/browser/ui/panels/panel_utils_cocoa.mm b/chrome/browser/ui/panels/panel_utils_cocoa.mm deleted file mode 100644 index f1d5990..0000000 --- a/chrome/browser/ui/panels/panel_utils_cocoa.mm +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 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. - -#import "chrome/browser/ui/panels/panel_utils_cocoa.h" - -namespace cocoa_utils { - -NSRect ConvertRectToCocoaCoordinates(const gfx::Rect& bounds) { - // Flip coordinates based on the primary screen. - NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; - - return NSMakeRect( - bounds.x(), NSHeight([screen frame]) - bounds.height() - bounds.y(), - bounds.width(), bounds.height()); -} - -NSPoint ConvertPointToCocoaCoordinates(const gfx::Point& point) { - // Flip coordinates based on the primary screen. - NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; - - return NSMakePoint(point.x(), NSHeight([screen frame]) - point.y()); -} - -gfx::Point ConvertPointFromCocoaCoordinates(NSPoint point) { - // Flip coordinates based on the primary screen. - NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; - - return gfx::Point(point.x, NSHeight([screen frame]) - point.y); -} - -} // namespace cocoa_utils diff --git a/chrome/browser/ui/panels/panel_window_controller_cocoa.h b/chrome/browser/ui/panels/panel_window_controller_cocoa.h index c806027..21fee91 100644 --- a/chrome/browser/ui/panels/panel_window_controller_cocoa.h +++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.h @@ -98,11 +98,11 @@ class PanelBrowserWindowCocoa; animate:(BOOL)animate; // Used by PanelTitlebarViewCocoa when user rearranges the Panels by dragging. -// |mouseLocation| is in Cocoa's screen coordinates. - (BOOL)isDraggable; -- (void)startDrag:(NSPoint)mouseLocation; +- (void)startDrag; - (void)endDrag:(BOOL)cancelled; -- (void)drag:(NSPoint)mouseLocation; +- (void)dragWithDeltaX:(int)deltaX + deltaY:(int)deltaY; // Accessor for titlebar view. - (PanelTitlebarViewCocoa*)titlebarView; diff --git a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm index 0576fcc..97f05e3 100644 --- a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm +++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm @@ -32,7 +32,6 @@ #include "chrome/browser/ui/panels/panel_settings_menu_model.h" #include "chrome/browser/ui/panels/panel_strip.h" #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" -#import "chrome/browser/ui/panels/panel_utils_cocoa.h" #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_service.h" @@ -409,15 +408,9 @@ enum { return windowShim_->panel()->draggable(); } -- (void)startDrag:(NSPoint)mouseLocation { +- (void)startDrag { animateOnBoundsChange_ = NO; - - // Convert from Cocoa's screen coordinates to platform-indepedent screen - // coordinates because PanelManager method takes platform-indepedent screen - // coordinates. - windowShim_->panel()->manager()->StartDragging( - windowShim_->panel(), - cocoa_utils::ConvertPointFromCocoaCoordinates(mouseLocation)); + windowShim_->panel()->manager()->StartDragging(windowShim_->panel()); } - (void)endDrag:(BOOL)cancelled { @@ -425,12 +418,9 @@ enum { windowShim_->panel()->manager()->EndDragging(cancelled); } -- (void)drag:(NSPoint)mouseLocation { - // Convert from Cocoa's screen coordinates to platform-indepedent screen - // coordinates because PanelManager method takes platform-indepedent screen - // coordinates. - windowShim_->panel()->manager()->Drag( - cocoa_utils::ConvertPointFromCocoaCoordinates(mouseLocation)); +- (void)dragWithDeltaX:(int)deltaX + deltaY:(int)deltaY { + windowShim_->panel()->manager()->Drag(deltaX, deltaY); } - (void)setPanelFrame:(NSRect)frame |