summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 03:55:50 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 03:55:50 +0000
commita94a94c85f9b1d110242035f54f3b3e9c90f2b28 (patch)
tree84db8655d04ab6372960fea57876e7e7d4b292dc /chrome/browser/ui
parent4eb74ce100e75920f61a9e88684acfbb8e433770 (diff)
downloadchromium_src-a94a94c85f9b1d110242035f54f3b3e9c90f2b28.zip
chromium_src-a94a94c85f9b1d110242035f54f3b3e9c90f2b28.tar.gz
chromium_src-a94a94c85f9b1d110242035f54f3b3e9c90f2b28.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/panels/detached_panel_browsertest.cc23
-rw-r--r--chrome/browser/ui/panels/native_panel.h6
-rw-r--r--chrome/browser/ui/panels/panel_browser_frame_view.cc14
-rw-r--r--chrome/browser/ui/panels/panel_browser_view.cc41
-rw-r--r--chrome/browser/ui/panels/panel_browser_view.h5
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa.mm39
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_gtk.cc22
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc38
-rw-r--r--chrome/browser/ui/panels/panel_drag_controller.cc14
-rw-r--r--chrome/browser/ui/panels/panel_drag_controller.h10
-rw-r--r--chrome/browser/ui/panels/panel_manager.cc9
-rw-r--r--chrome/browser/ui/panels/panel_manager.h5
-rw-r--r--chrome/browser/ui/panels/panel_titlebar_view_cocoa.h14
-rw-r--r--chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm48
-rw-r--r--chrome/browser/ui/panels/panel_utils_cocoa.h33
-rw-r--r--chrome/browser/ui/panels/panel_utils_cocoa.mm32
-rw-r--r--chrome/browser/ui/panels/panel_window_controller_cocoa.h6
-rw-r--r--chrome/browser/ui/panels/panel_window_controller_cocoa.mm20
18 files changed, 244 insertions, 135 deletions
diff --git a/chrome/browser/ui/panels/detached_panel_browsertest.cc b/chrome/browser/ui/panels/detached_panel_browsertest.cc
index 24e22c1..885cc1d 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());
- panel_testing->DragTitlebar(-51, 102);
- origin.Offset(-51, 102);
+ origin.Offset(-51, -102);
+ panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
- panel_testing->DragTitlebar(37, -42);
- origin.Offset(37, -42);
+ origin.Offset(37, 45);
+ panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
panel_testing->FinishDragTitlebar();
@@ -74,12 +74,13 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DragDetachedPanel) {
panel_testing->PressLeftMouseButtonTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
- panel_testing->DragTitlebar(-51, 102);
- origin.Offset(-51, 102);
+ origin.Offset(-51, -102);
+ panel_testing->DragTitlebar(origin);
+
EXPECT_EQ(origin, panel->GetBounds().origin());
- panel_testing->DragTitlebar(37, -42);
- origin.Offset(37, -42);
+ origin.Offset(37, 45);
+ panel_testing->DragTitlebar(origin);
EXPECT_EQ(origin, panel->GetBounds().origin());
panel_testing->CancelDragTitlebar();
@@ -118,7 +119,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) {
// Start dragging a panel.
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-51, -102);
+ panel1_testing->DragTitlebar(panel1_new_position);
EXPECT_TRUE(drag_controller->IsDragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
@@ -166,7 +167,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) {
// Start dragging a panel.
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-51, -102);
+ panel1_testing->DragTitlebar(panel1_new_position);
EXPECT_TRUE(drag_controller->IsDragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
@@ -208,7 +209,7 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CloseDetachedPanelOnDrag) {
// Start dragging a panel again.
panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-51, -102);
+ panel1_testing->DragTitlebar(panel1_new_position);
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 2298b77..a2eb4e0 100644
--- a/chrome/browser/ui/panels/native_panel.h
+++ b/chrome/browser/ui/panels/native_panel.h
@@ -96,9 +96,11 @@ class NativePanelTesting {
static NativePanelTesting* Create(NativePanel* native_panel);
virtual ~NativePanelTesting() {}
- virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) = 0;
+ // |mouse_location| is in screen coordinates.
+ virtual void PressLeftMouseButtonTitlebar(
+ const gfx::Point& mouse_location) = 0;
virtual void ReleaseMouseButtonTitlebar() = 0;
- virtual void DragTitlebar(int delta_x, int delta_y) = 0;
+ virtual void DragTitlebar(const gfx::Point& mouse_location) = 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 e5c7c50..f932c64 100644
--- a/chrome/browser/ui/panels/panel_browser_frame_view.cc
+++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc
@@ -594,15 +594,25 @@ 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(event.location())) {
+ panel_browser_view_->OnTitlebarMousePressed(mouse_location)) {
return true;
}
return BrowserNonClientFrameView::OnMousePressed(event);
}
bool PanelBrowserFrameView::OnMouseDragged(const views::MouseEvent& event) {
- if (panel_browser_view_->OnTitlebarMouseDragged(event.location()))
+ // |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))
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 9873a24..92daaa3 100644
--- a/chrome/browser/ui/panels/panel_browser_view.cc
+++ b/chrome/browser/ui/panels/panel_browser_view.cc
@@ -427,19 +427,17 @@ PanelBrowserFrameView* PanelBrowserView::GetFrameView() const {
return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView());
}
-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_);
-
+bool PanelBrowserView::OnTitlebarMousePressed(
+ const gfx::Point& 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& location) {
+bool PanelBrowserView::OnTitlebarMouseDragged(
+ const gfx::Point& mouse_location) {
if (!mouse_pressed_)
return false;
@@ -447,11 +445,7 @@ bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) {
return true;
gfx::Point last_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_);
+ mouse_location_ = mouse_location;
int delta_x = mouse_location_.x() - last_mouse_location.x();
int delta_y = mouse_location_.y() - last_mouse_location.y();
@@ -462,11 +456,11 @@ bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) {
old_focused_view_ = GetFocusManager()->GetFocusedView();
GetFocusManager()->SetFocusedView(GetFrameView());
- panel_->manager()->StartDragging(panel_.get());
+ panel_->manager()->StartDragging(panel_.get(), last_mouse_location);
mouse_dragging_state_ = DRAGGING_STARTED;
}
if (mouse_dragging_state_ == DRAGGING_STARTED)
- panel_->manager()->Drag(delta_x, delta_y);
+ panel_->manager()->Drag(mouse_location_);
return true;
}
@@ -550,9 +544,9 @@ class NativePanelTestingWin : public NativePanelTesting {
private:
virtual void PressLeftMouseButtonTitlebar(
- const gfx::Point& point) OVERRIDE;
+ const gfx::Point& mouse_location) OVERRIDE;
virtual void ReleaseMouseButtonTitlebar() OVERRIDE;
- virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE;
+ virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE;
virtual void CancelDragTitlebar() OVERRIDE;
virtual void FinishDragTitlebar() OVERRIDE;
virtual bool VerifyDrawingAttention() const OVERRIDE;
@@ -577,23 +571,16 @@ NativePanelTestingWin::NativePanelTestingWin(
}
void NativePanelTestingWin::PressLeftMouseButtonTitlebar(
- const gfx::Point& point) {
- panel_browser_view_->OnTitlebarMousePressed(point);
+ const gfx::Point& mouse_location) {
+ panel_browser_view_->OnTitlebarMousePressed(mouse_location);
}
void NativePanelTestingWin::ReleaseMouseButtonTitlebar() {
panel_browser_view_->OnTitlebarMouseReleased();
}
-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::DragTitlebar(const gfx::Point& mouse_location) {
+ panel_browser_view_->OnTitlebarMouseDragged(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 00798fb..e6e8dee 100644
--- a/chrome/browser/ui/panels/panel_browser_view.h
+++ b/chrome/browser/ui/panels/panel_browser_view.h
@@ -38,8 +38,9 @@ class PanelBrowserView : public BrowserView,
// Called from frame view when titlebar receives a mouse event.
// Return true if the event is handled.
- bool OnTitlebarMousePressed(const gfx::Point& location);
- bool OnTitlebarMouseDragged(const gfx::Point& location);
+ // |mouse_location| is in screen coordinates.
+ bool OnTitlebarMousePressed(const gfx::Point& mouse_location);
+ bool OnTitlebarMouseDragged(const gfx::Point& mouse_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 5f5a068..ff041d3 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
@@ -13,6 +13,7 @@
#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"
@@ -26,19 +27,6 @@ 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
@@ -97,7 +85,7 @@ void PanelBrowserWindowCocoa::ShowPanelInactive() {
SetPanelBoundsInstantly(bounds_);
is_shown_ = true;
- NSRect finalFrame = ConvertCoordinatesToCocoa(bounds_);
+ NSRect finalFrame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds_);
[controller_ revealAnimatedWithFrame:finalFrame];
}
@@ -124,7 +112,7 @@ void PanelBrowserWindowCocoa::setBoundsInternal(const gfx::Rect& bounds,
bounds_ = bounds;
- NSRect frame = ConvertCoordinatesToCocoa(bounds);
+ NSRect frame = cocoa_utils::ConvertRectToCocoaCoordinates(bounds);
[controller_ setPanelFrame:frame animate:animate];
}
@@ -315,9 +303,10 @@ class NativePanelTestingCocoa : public NativePanelTesting {
NativePanelTestingCocoa(NativePanel* native_panel);
virtual ~NativePanelTestingCocoa() { }
// Overridden from NativePanelTesting
- virtual void PressLeftMouseButtonTitlebar(const gfx::Point& point) OVERRIDE;
+ virtual void PressLeftMouseButtonTitlebar(
+ const gfx::Point& mouse_location) OVERRIDE;
virtual void ReleaseMouseButtonTitlebar() OVERRIDE;
- virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE;
+ virtual void DragTitlebar(const gfx::Point& mouse_location) OVERRIDE;
virtual void CancelDragTitlebar() OVERRIDE;
virtual void FinishDragTitlebar() OVERRIDE;
virtual bool VerifyDrawingAttention() const OVERRIDE;
@@ -345,16 +334,24 @@ PanelTitlebarViewCocoa* NativePanelTestingCocoa::titlebar() const {
}
void NativePanelTestingCocoa::PressLeftMouseButtonTitlebar(
- const gfx::Point& point) {
- [titlebar() 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)];
}
void NativePanelTestingCocoa::ReleaseMouseButtonTitlebar() {
[titlebar() releaseLeftMouseButtonTitlebar];
}
-void NativePanelTestingCocoa::DragTitlebar(int delta_x, int delta_y) {
- [titlebar() dragTitlebarDeltaX:delta_x deltaY:delta_y];
+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::CancelDragTitlebar() {
diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc
index f84b84f..8be2f47 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());
+ panel_->manager()->StartDragging(panel_.get(), gfx::Point(old_x, old_y));
}
if (drag_widget_) {
- panel_->manager()->Drag(new_x - old_x, new_y - old_y);
+ panel_->manager()->Drag(gfx::Point(new_x, new_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& point) OVERRIDE;
+ const gfx::Point& mouse_location) OVERRIDE;
virtual void ReleaseMouseButtonTitlebar() OVERRIDE;
- virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE;
+ virtual void DragTitlebar(const gfx::Point& mouse_location) 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& point) {
+ const gfx::Point& mouse_location) {
// 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 = point.x();
- event->button.y_root = point.y();
+ event->button.x_root = mouse_location.x();
+ event->button.y_root = mouse_location.y();
panel_browser_window_gtk_->OnTitlebarButtonPressEvent(
panel_browser_window_gtk_->titlebar_widget(),
reinterpret_cast<GdkEventButton*>(event));
@@ -829,15 +829,13 @@ void NativePanelTestingGtk::ReleaseMouseButtonTitlebar() {
MessageLoopForUI::current()->RunAllPending();
}
-void NativePanelTestingGtk::DragTitlebar(int delta_x, int delta_y) {
+void NativePanelTestingGtk::DragTitlebar(const gfx::Point& mouse_location) {
// 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);
- 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;
+ event->motion.x_root = mouse_location.x();
+ event->motion.y_root = mouse_location.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 c860e85..fbd7771 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -178,13 +178,15 @@ 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(
- panels[drag_index]->GetBounds().origin());
+ test_dragging_mouse_location_);
EXPECT_EQ(test_begin_bounds, GetPanelBounds(panels));
}
// Trigger the drag.
- panel_testing_to_drag->DragTitlebar(delta_x, delta_y);
+ test_dragging_mouse_location_.Offset(delta_x, delta_y);
+ panel_testing_to_drag->DragTitlebar(test_dragging_mouse_location_);
// Compare against expected bounds.
EXPECT_EQ(AddXDeltaToBounds(test_begin_bounds, expected_delta_x_after_drag),
@@ -405,6 +407,12 @@ 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) {
@@ -778,9 +786,11 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, NotDraggable) {
scoped_ptr<NativePanelTesting> panel_testing(
NativePanelTesting::Create(panel->native_panel()));
gfx::Rect bounds = panel->GetBounds();
- panel_testing->PressLeftMouseButtonTitlebar(bounds.origin());
+ gfx::Point mouse_location = bounds.origin();
+ panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
EXPECT_EQ(bounds.x(), panel->GetBounds().x());
- panel_testing->DragTitlebar(-50, 10);
+ mouse_location.Offset(-50, 10);
+ panel_testing->DragTitlebar(mouse_location);
EXPECT_EQ(bounds.x(), panel->GetBounds().x());
panel_testing->FinishDragTitlebar();
EXPECT_EQ(bounds.x(), panel->GetBounds().x());
@@ -796,7 +806,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) {
PanelDragController* drag_controller = panel_manager->drag_controller();
DockedPanelStrip* docked_strip = panel_manager->docked_strip();
- // Create 4 detached panels.
+ // Create 4 docked 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));
@@ -819,8 +829,10 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) {
// Start dragging a panel.
// We have: P1* P4 P3 P2
- panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-500, -5);
+ gfx::Point mouse_location = panel1->GetBounds().origin();
+ panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
+ mouse_location.Offset(-500, -5);
+ panel1_testing->DragTitlebar(mouse_location);
EXPECT_TRUE(drag_controller->IsDragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
@@ -874,8 +886,10 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) {
// Start dragging a panel.
// We have: P1* P4 P3
- panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-500, -5);
+ gfx::Point mouse_location = panel1->GetBounds().origin();
+ panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
+ mouse_location.Offset(-500, -5);
+ panel1_testing->DragTitlebar(mouse_location);
EXPECT_TRUE(drag_controller->IsDragging());
EXPECT_EQ(panel1, drag_controller->dragging_panel());
@@ -923,8 +937,10 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CloseDockedPanelOnDrag) {
// Start dragging a panel again.
// We have: P1* P4
- panel1_testing->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin());
- panel1_testing->DragTitlebar(-500, -5);
+ gfx::Point mouse_location = panel1->GetBounds().origin();
+ panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
+ mouse_location.Offset(-500, -5);
+ panel1_testing->DragTitlebar(mouse_location);
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 2a21cd28..7cd0990 100644
--- a/chrome/browser/ui/panels/panel_drag_controller.cc
+++ b/chrome/browser/ui/panels/panel_drag_controller.cc
@@ -15,20 +15,28 @@ PanelDragController::PanelDragController()
PanelDragController::~PanelDragController() {
}
-void PanelDragController::StartDragging(Panel* panel) {
+void PanelDragController::StartDragging(Panel* panel,
+ const gfx::Point& mouse_location) {
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(int delta_x, int delta_y) {
+void PanelDragController::Drag(const gfx::Point& mouse_location) {
DCHECK(dragging_panel_);
- dragging_panel_->panel_strip()->DragPanel(dragging_panel_, delta_x, delta_y);
+ 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;
}
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 a58b764..df944a5 100644
--- a/chrome/browser/ui/panels/panel_drag_controller.h
+++ b/chrome/browser/ui/panels/panel_drag_controller.h
@@ -19,8 +19,10 @@ class PanelDragController {
PanelDragController();
~PanelDragController();
- void StartDragging(Panel* panel);
- void Drag(int delta_x, int delta_y);
+ // 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 EndDragging(bool cancelled);
// Asynchronous confirmation of panel having been closed.
@@ -42,6 +44,10 @@ 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 22195b6..3fc9ebb 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -161,12 +161,13 @@ void PanelManager::OnPanelClosed(Panel* panel) {
content::NotificationService::NoDetails());
}
-void PanelManager::StartDragging(Panel* panel) {
- drag_controller_->StartDragging(panel);
+void PanelManager::StartDragging(Panel* panel,
+ const gfx::Point& mouse_location) {
+ drag_controller_->StartDragging(panel, mouse_location);
}
-void PanelManager::Drag(int delta_x, int delta_y) {
- drag_controller_->Drag(delta_x, delta_y);
+void PanelManager::Drag(const gfx::Point& mouse_location) {
+ drag_controller_->Drag(mouse_location);
}
void PanelManager::EndDragging(bool cancelled) {
diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h
index 3194cf8..f368ece 100644
--- a/chrome/browser/ui/panels/panel_manager.h
+++ b/chrome/browser/ui/panels/panel_manager.h
@@ -46,8 +46,9 @@ class PanelManager : public AutoHidingDesktopBar::Observer {
void OnPanelClosed(Panel* panel);
// Drags the given panel.
- void StartDragging(Panel* panel);
- void Drag(int delta_x, int delta_y);
+ // |mouse_location| is in screen coordinate system.
+ void StartDragging(Panel* panel, const gfx::Point& mouse_location);
+ void Drag(const gfx::Point& mouse_location);
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 a93f5b8..e6f83bf 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_;
+ NSPoint dragStartLocation_; // in cocoa's screen coordinates.
// "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.
-- (void)startDrag;
+// |mouseLocation| is in Cocoa's screen coordinates.
+- (void)startDrag:(NSPoint)mouseLocation;
- (void)endDrag:(BOOL)cancelled;
-- (void)dragWithDeltaX:(int)deltaX
- deltaY:(int)deltaY;
+- (void)drag:(NSPoint)mouseLocation;
// Update the visibility of settings button.
- (void)updateSettingsButtonVisibility:(BOOL)mouseOverWindow;
@@ -122,10 +122,10 @@ enum PanelDragState {
- (void)simulateCloseButtonClick;
// NativePanelTesting support.
-- (void)pressLeftMouseButtonTitlebar;
+// |mouseLocation| is in Cocoa's screen coordinates.
+- (void)pressLeftMouseButtonTitlebar:(NSPoint)mouseLocation;
- (void)releaseLeftMouseButtonTitlebar;
-- (void)dragTitlebarDeltaX:(double)delta_x
- deltaY:(double)delta_y;
+- (void)dragTitlebar:(NSPoint)mouseLocation;
- (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 f637494..6b1ba0f 100644
--- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
@@ -392,7 +392,8 @@ static NSEvent* MakeMouseEvent(NSEventType type,
- (void)mouseDown:(NSEvent*)event {
if ([controller_ isDraggable]) {
dragState_ = PANEL_DRAG_CAN_START;
- dragStartLocation_ = [event locationInWindow];
+ dragStartLocation_ =
+ [[self window] convertBaseToScreen:[event locationInWindow]];
}
}
@@ -404,8 +405,8 @@ static NSEvent* MakeMouseEvent(NSEventType type,
}
- (BOOL)exceedsDragThreshold:(NSPoint)mouseLocation {
- float deltaX = dragStartLocation_.x - mouseLocation.x;
- float deltaY = dragStartLocation_.y - mouseLocation.y;
+ float deltaX = fabs(dragStartLocation_.x - mouseLocation.x);
+ float deltaY = fabs(dragStartLocation_.y - mouseLocation.y);
return deltaX > kDragThreshold || deltaY > kDragThreshold;
}
@@ -430,15 +431,19 @@ static NSEvent* MakeMouseEvent(NSEventType type,
dequeue:YES];
switch ([event type]) {
- case NSLeftMouseDragged:
+ case NSLeftMouseDragged: {
+ // Get current mouse location in Cocoa's screen coordinates.
+ NSPoint mouseLocation =
+ [[self window] convertBaseToScreen:[event locationInWindow]];
if (dragState_ == PANEL_DRAG_CAN_START) {
- if (![self exceedsDragThreshold:[event locationInWindow]])
+ if (![self exceedsDragThreshold:mouseLocation])
return; // Don't start real drag yet.
- [self startDrag];
+ [self startDrag:dragStartLocation_];
}
- [self dragWithDeltaX:[event deltaX]
- deltaY:[event deltaY]];
+ DCHECK(dragState_ == PANEL_DRAG_IN_PROGRESS);
+ [self drag:mouseLocation];
break;
+ }
case NSKeyUp:
if ([event keyCode] == kVK_Escape) {
@@ -468,10 +473,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
}
}
-- (void)startDrag {
+- (void)startDrag:(NSPoint)mouseLocation {
DCHECK(dragState_ == PANEL_DRAG_CAN_START);
dragState_ = PANEL_DRAG_IN_PROGRESS;
- [controller_ startDrag];
+ [controller_ startDrag:mouseLocation];
}
- (void)endDrag:(BOOL)cancelled {
@@ -480,12 +485,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
dragState_ = PANEL_DRAG_SUPPRESSED;
}
-- (void)dragWithDeltaX:(int)deltaX
- deltaY:(int)deltaY {
+- (void)drag:(NSPoint)mouseLocation {
if (dragState_ != PANEL_DRAG_IN_PROGRESS)
return;
- [controller_ dragWithDeltaX:deltaX
- deltaY:deltaY];
+ [controller_ drag:mouseLocation];
}
- (void)drawAttention {
@@ -569,8 +572,11 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[[closeButton_ cell] performClick:closeButton_];
}
-- (void)pressLeftMouseButtonTitlebar {
- NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0);
+- (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);
[self mouseDown:event];
}
@@ -579,12 +585,12 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[self mouseUp:event];
}
-- (void)dragTitlebarDeltaX:(double)delta_x
- deltaY:(double)delta_y {
+- (void)dragTitlebar:(NSPoint)mouseLocation {
if (dragState_ == PANEL_DRAG_CAN_START)
- [self startDrag];
- [self dragWithDeltaX:delta_x
- deltaY:delta_y];
+ [self startDrag:dragStartLocation_];
+ // No need to do any conversion since |mouseLocation| is already in Cocoa's
+ // screen coordinates.
+ [self drag:mouseLocation];
}
- (void)cancelDragTitlebar {
diff --git a/chrome/browser/ui/panels/panel_utils_cocoa.h b/chrome/browser/ui/panels/panel_utils_cocoa.h
new file mode 100644
index 0000000..47a186b
--- /dev/null
+++ b/chrome/browser/ui/panels/panel_utils_cocoa.h
@@ -0,0 +1,33 @@
+// 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
new file mode 100644
index 0000000..f1d5990
--- /dev/null
+++ b/chrome/browser/ui/panels/panel_utils_cocoa.mm
@@ -0,0 +1,32 @@
+// 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 21fee91..c806027 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;
+- (void)startDrag:(NSPoint)mouseLocation;
- (void)endDrag:(BOOL)cancelled;
-- (void)dragWithDeltaX:(int)deltaX
- deltaY:(int)deltaY;
+- (void)drag:(NSPoint)mouseLocation;
// 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 97f05e3..0576fcc 100644
--- a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm
@@ -32,6 +32,7 @@
#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"
@@ -408,9 +409,15 @@ enum {
return windowShim_->panel()->draggable();
}
-- (void)startDrag {
+- (void)startDrag:(NSPoint)mouseLocation {
animateOnBoundsChange_ = NO;
- windowShim_->panel()->manager()->StartDragging(windowShim_->panel());
+
+ // 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));
}
- (void)endDrag:(BOOL)cancelled {
@@ -418,9 +425,12 @@ enum {
windowShim_->panel()->manager()->EndDragging(cancelled);
}
-- (void)dragWithDeltaX:(int)deltaX
- deltaY:(int)deltaY {
- windowShim_->panel()->manager()->Drag(deltaX, deltaY);
+- (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)setPanelFrame:(NSRect)frame