diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:17:23 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:17:23 +0000 |
commit | 79cea75c62c965f11926b723b77c3ecdf39f4a42 (patch) | |
tree | 253265acc0184950ea9143e5426f5445b6e54b00 /ash | |
parent | a281638a8fa79d4eeee796a46188f0df37903910 (diff) | |
download | chromium_src-79cea75c62c965f11926b723b77c3ecdf39f4a42.zip chromium_src-79cea75c62c965f11926b723b77c3ecdf39f4a42.tar.gz chromium_src-79cea75c62c965f11926b723b77c3ecdf39f4a42.tar.bz2 |
Fix coordinates in tab detach/drag and multi window resizer.
ToplevelWindowEventFilter:
* Use location in root window for drag_location
DocInfo::GetLocalProcessWindowAtPoint
* Use ScreenPositionClient to convert a point in screen to window
* Use correct root window at the position.
MultiWindowResizer
* Use ScreenPositionClient to convert a point in screen to window.
* show_bounds_ should be screen coordinates.
I also renamed {screen|parent}_{location|position| to
{location|position}_in_{screen|parent} to be more explicit and consistent with the rest of the code.
I'll work on the test separately as we discussed offline.
BUG=138997,138868
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/10827022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148478 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/screen_ash.h | 6 | ||||
-rw-r--r-- | ash/wm/toplevel_window_event_filter.cc | 15 | ||||
-rw-r--r-- | ash/wm/toplevel_window_event_filter.h | 2 | ||||
-rw-r--r-- | ash/wm/workspace/multi_window_resize_controller.cc | 74 | ||||
-rw-r--r-- | ash/wm/workspace/multi_window_resize_controller.h | 25 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_event_filter.cc | 4 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_event_filter.h | 7 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer.cc | 4 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer.h | 2 |
9 files changed, 75 insertions, 64 deletions
diff --git a/ash/screen_ash.h b/ash/screen_ash.h index d150d4b..8c57322 100644 --- a/ash/screen_ash.h +++ b/ash/screen_ash.h @@ -7,10 +7,12 @@ #include "ash/ash_export.h" #include "base/compiler_specific.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" #include "ui/gfx/screen_impl.h" +namespace gfx { +class Rect; +} + namespace ash { // Aura implementation of gfx::Screen. Implemented here to avoid circular diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc index c950036..8d0ee8d 100644 --- a/ash/wm/toplevel_window_event_filter.cc +++ b/ash/wm/toplevel_window_event_filter.cc @@ -80,10 +80,10 @@ bool ToplevelWindowEventFilter::PreHandleMouseEvent(aura::Window* target, if ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && WindowResizer::GetBoundsChangeForWindowComponent(component)) { - gfx::Point parent_location( + gfx::Point location_in_parent( ConvertPointToParent(target, event->location())); window_resizer_.reset( - CreateWindowResizer(target, parent_location, component)); + CreateWindowResizer(target, location_in_parent, component)); } else { window_resizer_.reset(); } @@ -136,10 +136,10 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( return ui::GESTURE_STATUS_UNKNOWN; } in_gesture_resize_ = true; - gfx::Point parent_location( + gfx::Point location_in_parent( ConvertPointToParent(target, event->location())); window_resizer_.reset( - CreateWindowResizer(target, parent_location, component)); + CreateWindowResizer(target, location_in_parent, component)); break; } case ui::ET_GESTURE_SCROLL_UPDATE: { @@ -209,7 +209,7 @@ void ToplevelWindowEventFilter::RunMoveLoop(aura::Window* source) { GetLastTouchPointForTarget(source, &drag_location); DCHECK(has_point); } else { - drag_location = gfx::Screen::GetCursorScreenPoint(); + drag_location = root_window->GetLastMouseLocationInRoot(); aura::Window::ConvertPointToWindow( root_window, source->parent(), &drag_location); } @@ -241,11 +241,12 @@ void ToplevelWindowEventFilter::EndMoveLoop() { // static WindowResizer* ToplevelWindowEventFilter::CreateWindowResizer( aura::Window* window, - const gfx::Point& point, + const gfx::Point& point_in_parent, int window_component) { if (!wm::IsWindowNormal(window)) return NULL; // Don't allow resizing/dragging maximized/fullscreen windows. - return DefaultWindowResizer::Create(window, point, window_component); + return DefaultWindowResizer::Create( + window, point_in_parent, window_component); } void ToplevelWindowEventFilter::CompleteDrag(DragCompletionStatus status, diff --git a/ash/wm/toplevel_window_event_filter.h b/ash/wm/toplevel_window_event_filter.h index 4d33994..4576432 100644 --- a/ash/wm/toplevel_window_event_filter.h +++ b/ash/wm/toplevel_window_event_filter.h @@ -57,7 +57,7 @@ class ASH_EXPORT ToplevelWindowEventFilter : protected: // Creates a new WindowResizer. virtual WindowResizer* CreateWindowResizer(aura::Window* window, - const gfx::Point& point, + const gfx::Point& point_in_parent, int window_component); private: diff --git a/ash/wm/workspace/multi_window_resize_controller.cc b/ash/wm/workspace/multi_window_resize_controller.cc index a94da55..aa23b16 100644 --- a/ash/wm/workspace/multi_window_resize_controller.cc +++ b/ash/wm/workspace/multi_window_resize_controller.cc @@ -4,12 +4,14 @@ #include "ash/wm/workspace/multi_window_resize_controller.h" +#include "ash/screen_ash.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/wm/window_animations.h" #include "ash/wm/workspace/workspace_event_filter.h" #include "ash/wm/workspace/workspace_window_resizer.h" #include "grit/ui_resources.h" +#include "ui/aura/client/screen_position_client.h" #include "ui/aura/event_filter.h" #include "ui/aura/root_window.h" #include "ui/aura/shared/compound_event_filter.h" @@ -118,9 +120,9 @@ class MultiWindowResizeController::ResizeMouseWatcherHost : ResizeMouseWatcherHost(MultiWindowResizeController* host) : host_(host) {} // MouseWatcherHost overrides: - virtual bool Contains(const gfx::Point& screen_point, + virtual bool Contains(const gfx::Point& point_in_screen, MouseEventType type) OVERRIDE { - return host_->IsOverWindows(screen_point); + return host_->IsOverWindows(point_in_screen); } private: @@ -156,7 +158,7 @@ MultiWindowResizeController::~MultiWindowResizeController() { void MultiWindowResizeController::Show(Window* window, int component, - const gfx::Point& point) { + const gfx::Point& point_in_window) { // When the resize widget is showing we ignore Show() requests. Instead we // only care about mouse movements from MouseWatcher. This is necessary as // WorkspaceEventFilter only sees mouse movements over the windows, not all @@ -164,7 +166,7 @@ void MultiWindowResizeController::Show(Window* window, if (resize_widget_) return; - ResizeWindows windows(DetermineWindows(window, component, point)); + ResizeWindows windows(DetermineWindows(window, component, point_in_window)); if (IsShowing()) { if (windows_.Equals(windows)) return; // Over the same windows. @@ -177,8 +179,9 @@ void MultiWindowResizeController::Show(Window* window, windows_ = windows; windows_.window1->AddObserver(this); windows_.window2->AddObserver(this); - show_location_ = point; - Window::ConvertPointToWindow(window, window->parent(), &show_location_); + show_location_in_parent_ = point_in_window; + Window::ConvertPointToWindow( + window, window->parent(), &show_location_in_parent_); if (show_timer_.IsRunning()) return; show_timer_.Start(FROM_HERE, @@ -369,8 +372,10 @@ void MultiWindowResizeController::ShowNow() { WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); resize_widget_->GetNativeWindow()->SetName("MultiWindowResizeController"); resize_widget_->SetContentsView(view); - show_bounds_ = CalculateResizeWidgetBounds(show_location_); - resize_widget_->SetBounds(show_bounds_); + show_bounds_in_screen_ = ScreenAsh::ConvertRectToScreen( + windows_.window1->parent(), + CalculateResizeWidgetBounds(show_location_in_parent_)); + resize_widget_->SetBounds(show_bounds_in_screen_); resize_widget_->Show(); mouse_watcher_.reset(new views::MouseWatcher( new ResizeMouseWatcherHost(this), @@ -385,14 +390,13 @@ bool MultiWindowResizeController::IsShowing() const { } void MultiWindowResizeController::StartResize( - const gfx::Point& screen_location) { + const gfx::Point& location_in_screen) { DCHECK(!window_resizer_.get()); DCHECK(windows_.is_valid()); hide_timer_.Stop(); - gfx::Point parent_location(screen_location); - aura::Window::ConvertPointToWindow( - windows_.window1->GetRootWindow(), windows_.window1->parent(), - &parent_location); + gfx::Point location_in_parent(location_in_screen); + aura::client::GetScreenPositionClient(windows_.window2->GetRootWindow())-> + ConvertPointFromScreen(windows_.window2->parent(), &location_in_parent); std::vector<aura::Window*> windows; windows.push_back(windows_.window2); FindWindowsTouching(windows_.window2, windows_.direction, @@ -403,21 +407,23 @@ void MultiWindowResizeController::StartResize( } int component = windows_.direction == LEFT_RIGHT ? HTRIGHT : HTBOTTOM; window_resizer_.reset(WorkspaceWindowResizer::Create( - windows_.window1, parent_location, component, windows)); + windows_.window1, location_in_parent, component, windows)); } -void MultiWindowResizeController::Resize(const gfx::Point& screen_location, +void MultiWindowResizeController::Resize(const gfx::Point& location_in_screen, int event_flags) { - gfx::Point parent_location(screen_location); - aura::Window::ConvertPointToWindow(windows_.window1->GetRootWindow(), - windows_.window1->parent(), - &parent_location); - window_resizer_->Drag(parent_location, event_flags); - gfx::Rect bounds = CalculateResizeWidgetBounds(parent_location); + gfx::Point location_in_parent(location_in_screen); + aura::client::GetScreenPositionClient(windows_.window1->GetRootWindow())-> + ConvertPointFromScreen(windows_.window1->parent(), &location_in_parent); + window_resizer_->Drag(location_in_parent, event_flags); + gfx::Rect bounds = ScreenAsh::ConvertRectToScreen( + windows_.window1->parent(), + CalculateResizeWidgetBounds(location_in_parent)); + if (windows_.direction == LEFT_RIGHT) - bounds.set_y(show_bounds_.y()); + bounds.set_y(show_bounds_in_screen_.y()); else - bounds.set_x(show_bounds_.x()); + bounds.set_x(show_bounds_in_screen_.x()); resize_widget_->SetBounds(bounds); } @@ -440,21 +446,21 @@ void MultiWindowResizeController::CancelResize() { } gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( - const gfx::Point& location) const { + const gfx::Point& location_in_parent) const { gfx::Size pref = resize_widget_->GetContentsView()->GetPreferredSize(); int x = 0, y = 0; if (windows_.direction == LEFT_RIGHT) { x = windows_.window1->bounds().right() - pref.width() / 2; - y = location.y() + kResizeWidgetPadding; + y = location_in_parent.y() + kResizeWidgetPadding; if (y + pref.height() / 2 > windows_.window1->bounds().bottom() && y + pref.height() / 2 > windows_.window2->bounds().bottom()) { - y = location.y() - kResizeWidgetPadding - pref.height(); + y = location_in_parent.y() - kResizeWidgetPadding - pref.height(); } } else { - x = location.x() + kResizeWidgetPadding; + x = location_in_parent.x() + kResizeWidgetPadding; if (x + pref.height() / 2 > windows_.window1->bounds().right() && x + pref.height() / 2 > windows_.window2->bounds().right()) { - x = location.x() - kResizeWidgetPadding - pref.width(); + x = location_in_parent.x() - kResizeWidgetPadding - pref.width(); } y = windows_.window1->bounds().bottom() - pref.height() / 2; } @@ -462,11 +468,11 @@ gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds( } bool MultiWindowResizeController::IsOverWindows( - const gfx::Point& screen_location) const { + const gfx::Point& location_in_screen) const { if (window_resizer_.get()) return true; // Ignore hides while actively resizing. - if (resize_widget_->GetWindowBoundsInScreen().Contains(screen_location)) + if (resize_widget_->GetWindowBoundsInScreen().Contains(location_in_screen)) return true; int hit1, hit2; @@ -478,18 +484,18 @@ bool MultiWindowResizeController::IsOverWindows( hit2 = HTLEFT; } - return IsOverWindow(windows_.window1, screen_location, hit1) || - IsOverWindow(windows_.window2, screen_location, hit2); + return IsOverWindow(windows_.window1, location_in_screen, hit1) || + IsOverWindow(windows_.window2, location_in_screen, hit2); } bool MultiWindowResizeController::IsOverWindow( aura::Window* window, - const gfx::Point& screen_location, + const gfx::Point& location_in_screen, int component) const { if (!window->delegate()) return false; - gfx::Point window_loc(screen_location); + gfx::Point window_loc(location_in_screen); aura::Window::ConvertPointToWindow( window->GetRootWindow(), window, &window_loc); return window->HitTest(window_loc) && diff --git a/ash/wm/workspace/multi_window_resize_controller.h b/ash/wm/workspace/multi_window_resize_controller.h index f14e15a..1fb4b62 100644 --- a/ash/wm/workspace/multi_window_resize_controller.h +++ b/ash/wm/workspace/multi_window_resize_controller.h @@ -122,10 +122,10 @@ class ASH_EXPORT MultiWindowResizeController : bool IsShowing() const; // Initiates a resize. - void StartResize(const gfx::Point& screen_location); + void StartResize(const gfx::Point& location_in_screen); // Resizes to the new location. - void Resize(const gfx::Point& screen_location, int event_flags); + void Resize(const gfx::Point& location_in_screen, int event_flags); // Completes the resize. void CompleteResize(int event_flags); @@ -134,15 +134,16 @@ class ASH_EXPORT MultiWindowResizeController : void CancelResize(); // Returns the bounds for the resize widget. - gfx::Rect CalculateResizeWidgetBounds(const gfx::Point& location) const; + gfx::Rect CalculateResizeWidgetBounds( + const gfx::Point& location_in_parent) const; - // Returns true if |screen_location| is over the resize windows (or the resize - // widget itself). - bool IsOverWindows(const gfx::Point& screen_location) const; + // Returns true if |location_in_screen| is over the resize windows + // (or the resize widget itself). + bool IsOverWindows(const gfx::Point& location_in_screen) const; - // Returns true if |screen_location| is over |window|. + // Returns true if |location_in_screen| is over |window|. bool IsOverWindow(aura::Window* window, - const gfx::Point& screen_location, + const gfx::Point& location_in_screen, int component) const; // Windows and direction to resize. @@ -159,11 +160,11 @@ class ASH_EXPORT MultiWindowResizeController : // If non-null we're in a resize loop. scoped_ptr<WorkspaceWindowResizer> window_resizer_; - // Mouse coordinate passed to Show(). - gfx::Point show_location_; + // Mouse coordinate passed to Show() in container's coodinates. + gfx::Point show_location_in_parent_; - // Bounds the widget was last shown at. - gfx::Rect show_bounds_; + // Bounds the widget was last shown at in screen coordinates. + gfx::Rect show_bounds_in_screen_; // Size of the grid. int grid_size_; diff --git a/ash/wm/workspace/workspace_event_filter.cc b/ash/wm/workspace/workspace_event_filter.cc index ae9459c..89218a1 100644 --- a/ash/wm/workspace/workspace_event_filter.cc +++ b/ash/wm/workspace/workspace_event_filter.cc @@ -117,7 +117,7 @@ void WorkspaceEventFilter::OnWindowDestroyed(aura::Window* window) { WindowResizer* WorkspaceEventFilter::CreateWindowResizer( aura::Window* window, - const gfx::Point& point, + const gfx::Point& point_in_parent, int window_component) { // Allow dragging maximized windows if it's not tracked by workspace. This is // set by tab dragging code. @@ -126,7 +126,7 @@ WindowResizer* WorkspaceEventFilter::CreateWindowResizer( return NULL; } return WorkspaceWindowResizer::Create( - window, point, window_component, + window, point_in_parent, window_component, std::vector<aura::Window*>()); } diff --git a/ash/wm/workspace/workspace_event_filter.h b/ash/wm/workspace/workspace_event_filter.h index 0b1b740..25051b7 100644 --- a/ash/wm/workspace/workspace_event_filter.h +++ b/ash/wm/workspace/workspace_event_filter.h @@ -34,9 +34,10 @@ class WorkspaceEventFilter : public ToplevelWindowEventFilter, protected: // Overridden from ToplevelWindowEventFilter: - virtual WindowResizer* CreateWindowResizer(aura::Window* window, - const gfx::Point& point, - int window_component) OVERRIDE; + virtual WindowResizer* CreateWindowResizer( + aura::Window* window, + const gfx::Point& point_in_parent, + int window_component) OVERRIDE; private: friend class WorkspaceEventFilterTestHelper; diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc index 78f109bb..a683465 100644 --- a/ash/wm/workspace/workspace_window_resizer.cc +++ b/ash/wm/workspace/workspace_window_resizer.cc @@ -52,10 +52,10 @@ WorkspaceWindowResizer::~WorkspaceWindowResizer() { // static WorkspaceWindowResizer* WorkspaceWindowResizer::Create( aura::Window* window, - const gfx::Point& location, + const gfx::Point& location_in_parent, int window_component, const std::vector<aura::Window*>& attached_windows) { - Details details(window, location, window_component); + Details details(window, location_in_parent, window_component); return details.is_resizable ? new WorkspaceWindowResizer(details, attached_windows) : NULL; } diff --git a/ash/wm/workspace/workspace_window_resizer.h b/ash/wm/workspace/workspace_window_resizer.h index 1edf10dc..3b28e1e 100644 --- a/ash/wm/workspace/workspace_window_resizer.h +++ b/ash/wm/workspace/workspace_window_resizer.h @@ -37,7 +37,7 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { static WorkspaceWindowResizer* Create( aura::Window* window, - const gfx::Point& location, + const gfx::Point& location_in_parent, int window_component, const std::vector<aura::Window*>& attached_windows); |