diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 18:33:24 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 18:33:24 +0000 |
commit | ceb36f7d5cec71407b265aba887cd64216d24731 (patch) | |
tree | ea977c72eb7882c1629a5c78f56b1a9e7e3e6b60 | |
parent | 80211f670f34191d80b875086aaf7b5b06a743d4 (diff) | |
download | chromium_src-ceb36f7d5cec71407b265aba887cd64216d24731.zip chromium_src-ceb36f7d5cec71407b265aba887cd64216d24731.tar.gz chromium_src-ceb36f7d5cec71407b265aba887cd64216d24731.tar.bz2 |
Add Vector2d classes that represent offsets, instead of using Point.
Previously Point served two purposes, to be a position in 2d space, and also
an offset from the origin. This introduces a Vector2d class to represent an
offset, allowing typesafety checks for geometric operations.
The following are now the case:
Point +/- Vector = Point
- A point plus/minus an offset gives you a point at a position offset by the
vector.
Vector +/- Vector = Vector
- Two offsets can be added together to make a new offset.
Point - Point = Vector
- Subtracting one point from another gives you the offset between the two
points.
We add some new methods to perform these operations:
Rect::OffsetFromOrigin() gives the offset between the position of the rect
and the origin.
Point::OffsetFromOrigin() gives the offset between the point and the origin.
PointAtOffsetFromOrigin(Vector2d) converts a Vector2d to a Point at the given
offset away from the origin.
Rect::Offset(), Point::Add(), and Point::Subtract() now receive a Vector2d
instead of a point.
BUG=147395
R=sky
Review URL: https://codereview.chromium.org/11269022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165198 0039d316-1c4b-4281-b951-d872f2087c98
166 files changed, 1112 insertions, 489 deletions
@@ -199,7 +199,8 @@ 'filepath': 'ui/gfx/rect|'\ 'ui/gfx/point|'\ 'ui/gfx/size|'\ - 'ui/gfx/transform', + 'ui/gfx/transform|'\ + 'ui/gfx/vector2d', }, 'gpu': { 'filepath': 'gpu/', diff --git a/ash/display/multi_display_manager.cc b/ash/display/multi_display_manager.cc index 5911ae9..d155aed 100644 --- a/ash/display/multi_display_manager.cc +++ b/ash/display/multi_display_manager.cc @@ -511,7 +511,7 @@ void MultiDisplayManager::EnsurePointerInDisplays() { return; gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); gfx::Point target_location; - int64 closest_distance = -1; + int64 closest_distance_squared = -1; for (DisplayList::const_iterator iter = displays_.begin(); iter != displays_.end(); ++iter) { @@ -522,14 +522,16 @@ void MultiDisplayManager::EnsurePointerInDisplays() { break; } gfx::Point center = display_bounds.CenterPoint(); - gfx::Point diff = center.Subtract(location_in_screen); - // Use the distance from the center of the dislay. This is not + // Use the distance squared from the center of the dislay. This is not // exactly "closest" display, but good enough to pick one // appropriate (and there are at most two displays). - int64 distance = diff.x() * diff.x() + diff.y() * diff.y(); - if (closest_distance < 0 || closest_distance > distance) { + // We don't care about actual distance, only relative to other displays, so + // using the LengthSquared() is cheaper than Length(). + int64 distance_squared = (center - location_in_screen).LengthSquared(); + if (closest_distance_squared < 0 || + closest_distance_squared > distance_squared) { target_location = center; - closest_distance = distance; + closest_distance_squared = distance_squared; } } diff --git a/ash/drag_drop/drag_drop_controller.h b/ash/drag_drop/drag_drop_controller.h index 59f1f32..4c32696 100644 --- a/ash/drag_drop/drag_drop_controller.h +++ b/ash/drag_drop/drag_drop_controller.h @@ -88,7 +88,7 @@ class ASH_EXPORT DragDropController void Cleanup(); scoped_ptr<DragImageView> drag_image_; - gfx::Point drag_image_offset_; + gfx::Vector2d drag_image_offset_; const ui::OSExchangeData* drag_data_; int drag_operation_; diff --git a/ash/launcher/launcher_tooltip_manager_unittest.cc b/ash/launcher/launcher_tooltip_manager_unittest.cc index 8d63320..225d55f 100644 --- a/ash/launcher/launcher_tooltip_manager_unittest.cc +++ b/ash/launcher/launcher_tooltip_manager_unittest.cc @@ -195,7 +195,7 @@ TEST_F(LauncherTooltipManagerTest, HideForMouseEvent) { EXPECT_TRUE(TooltipIsVisible()); // Should hide if the mouse is out of the tooltip. - test_api.set_location(tooltip_rect.origin().Add(gfx::Point(-1, -1))); + test_api.set_location(tooltip_rect.origin().Add(gfx::Vector2d(-1, -1))); EXPECT_FALSE(event_filter->PreHandleMouseEvent(root_window, &mouse_event)); RunAllPendingInMessageLoop(); EXPECT_FALSE(TooltipIsVisible()); diff --git a/ash/launcher/overflow_bubble.cc b/ash/launcher/overflow_bubble.cc index 1161e16..b6e7abb 100644 --- a/ash/launcher/overflow_bubble.cc +++ b/ash/launcher/overflow_bubble.cc @@ -84,7 +84,7 @@ class OverflowBubbleView : public views::BubbleDelegateView { ShelfAlignment shelf_alignment_; LauncherView* launcher_view_; // Owned by views hierarchy. - gfx::Point scroll_offset_; + gfx::Vector2d scroll_offset_; DISALLOW_COPY_AND_ASSIGN(OverflowBubbleView); }; @@ -166,8 +166,8 @@ gfx::Size OverflowBubbleView::GetPreferredSize() { } void OverflowBubbleView::Layout() { - const gfx::Point origin(-scroll_offset_.x(), -scroll_offset_.y()); - launcher_view_->SetBoundsRect(gfx::Rect(origin, GetContentsSize())); + launcher_view_->SetBoundsRect(gfx::Rect( + gfx::PointAtOffsetFromOrigin(-scroll_offset_), GetContentsSize())); } void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) { diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc index 45c4785..0449645 100644 --- a/ash/tooltips/tooltip_controller.cc +++ b/ash/tooltips/tooltip_controller.cc @@ -450,9 +450,8 @@ void TooltipController::UpdateIfRequired() { GetTooltip()->Hide(); } else { string16 tooltip_text(tooltip_text_); - gfx::Point widget_loc = curr_mouse_loc_; - widget_loc = widget_loc.Add( - tooltip_window_->GetBoundsInScreen().origin()); + gfx::Point widget_loc = curr_mouse_loc_.Add( + tooltip_window_->GetBoundsInScreen().OffsetFromOrigin()); GetTooltip()->SetText(tooltip_text, widget_loc); GetTooltip()->Show(); tooltip_shown_timer_.Start(FROM_HERE, diff --git a/ash/wm/gestures/long_press_affordance_handler.cc b/ash/wm/gestures/long_press_affordance_handler.cc index 5c4e09d..f776e01 100644 --- a/ash/wm/gestures/long_press_affordance_handler.cc +++ b/ash/wm/gestures/long_press_affordance_handler.cc @@ -203,9 +203,9 @@ class LongPressAffordanceHandler::LongPressAffordanceView gfx::Transform scale; scale.SetScale(current_scale_, current_scale_); // We want to scale from the center. - canvas->Translate(gfx::Point(center.x(), center.y())); + canvas->Translate(center.OffsetFromOrigin()); canvas->Transform(scale); - canvas->Translate(gfx::Point(-center.x(), -center.y())); + canvas->Translate(-center.OffsetFromOrigin()); // Paint affordance glow int start_radius = kAffordanceInnerRadius - kAffordanceGlowWidth; diff --git a/ash/wm/toplevel_window_event_handler.cc b/ash/wm/toplevel_window_event_handler.cc index 948ed69..f84fd60 100644 --- a/ash/wm/toplevel_window_event_handler.cc +++ b/ash/wm/toplevel_window_event_handler.cc @@ -244,7 +244,7 @@ ui::EventResult ToplevelWindowEventHandler::OnGestureEvent( aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( aura::Window* source, - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. in_move_loop_ = true; move_cancelled_ = false; diff --git a/ash/wm/toplevel_window_event_handler.h b/ash/wm/toplevel_window_event_handler.h index efa66c5..142eca4 100644 --- a/ash/wm/toplevel_window_event_handler.h +++ b/ash/wm/toplevel_window_event_handler.h @@ -47,7 +47,7 @@ class ASH_EXPORT ToplevelWindowEventHandler // Overridden form aura::client::WindowMoveClient: virtual aura::client::WindowMoveResult RunMoveLoop( aura::Window* source, - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; // Overridden form ash::DisplayController::Observer: diff --git a/ash/wm/workspace/frame_maximize_button.cc b/ash/wm/workspace/frame_maximize_button.cc index 2319240..edb0a11 100644 --- a/ash/wm/workspace/frame_maximize_button.cc +++ b/ash/wm/workspace/frame_maximize_button.cc @@ -337,11 +337,9 @@ void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { void FrameMaximizeButton::ProcessUpdateEvent(const ui::LocatedEvent& event) { DCHECK(is_snap_enabled_); - int delta_x = event.x() - press_location_.x(); - int delta_y = event.y() - press_location_.y(); if (!exceeded_drag_threshold_) { - exceeded_drag_threshold_ = - views::View::ExceededDragThreshold(delta_x, delta_y); + exceeded_drag_threshold_ = views::View::ExceededDragThreshold( + event.location() - press_location_); } if (exceeded_drag_threshold_) UpdateSnap(event.location(), false); @@ -449,15 +447,14 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, SnapType FrameMaximizeButton::SnapTypeForLocation( const gfx::Point& location) const { MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); - int delta_x = location.x() - press_location_.x(); - int delta_y = location.y() - press_location_.y(); - if (!views::View::ExceededDragThreshold(delta_x, delta_y)) + gfx::Vector2d delta(location - press_location_); + if (!views::View::ExceededDragThreshold(delta)) return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; - else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) + if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x()) return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; - else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) + if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x()) return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; - else if (delta_y > 0) + if (delta.y() > 0) return SNAP_MINIMIZE; return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; } diff --git a/ash/wm/workspace/workspace_event_handler_unittest.cc b/ash/wm/workspace/workspace_event_handler_unittest.cc index 102268a..d67a123 100644 --- a/ash/wm/workspace/workspace_event_handler_unittest.cc +++ b/ash/wm/workspace/workspace_event_handler_unittest.cc @@ -154,10 +154,12 @@ TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) { aura::test::EventGenerator generator(window->GetRootWindow()); generator.MoveMouseToCenterOf(window.get()); generator.PressLeftButton(); - generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50))); + generator.MoveMouseTo( + generator.current_location().Add(gfx::Vector2d(50, 50))); DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString()); window.reset(); - generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50))); + generator.MoveMouseTo( + generator.current_location().Add(gfx::Vector2d(50, 50))); } // Verifies deleting the window while in a run loop doesn't crash. @@ -170,7 +172,7 @@ TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) { ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent())); MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); aura::client::GetWindowMoveClient(window->parent())->RunMoveLoop( - window.release(), gfx::Point()); + window.release(), gfx::Vector2d()); } } // namespace internal diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc index 686366f..3f19d5e 100644 --- a/cc/gl_renderer.cc +++ b/cc/gl_renderer.cc @@ -698,10 +698,8 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua float clampX = min(0.5, clampRect.width() / 2.0 - epsilon); float clampY = min(0.5, clampRect.height() / 2.0 - epsilon); clampRect.Inset(clampX, clampY, clampX, clampY); - gfx::PointF clampOffset = clampRect.origin() - tileRect.origin(); - gfx::PointF textureOffset = quad->textureOffset() + clampOffset + - (tileRect.origin() - quad->quadRect().origin()); + gfx::PointF textureOffset = quad->textureOffset() + clampRect.OffsetFromOrigin() - quad->quadRect().OffsetFromOrigin(); // Map clamping rectangle to unit square. float vertexTexTranslateX = -clampRect.x() / clampRect.width(); diff --git a/chrome/browser/automation/testing_automation_provider_gtk.cc b/chrome/browser/automation/testing_automation_provider_gtk.cc index 83f9843..dd380a6 100644 --- a/chrome/browser/automation/testing_automation_provider_gtk.cc +++ b/chrome/browser/automation/testing_automation_provider_gtk.cc @@ -35,16 +35,16 @@ void TestingAutomationProvider::WindowGetViewBounds(int handle, GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); *bounds = gfx::Rect(allocation.width, allocation.height); - gint x, y; + gfx::Point origin; if (screen_coordinates) { - gfx::Point point = ui::GetWidgetScreenPosition(widget); - x = point.x(); - y = point.y(); + origin = gfx::PointAtOffsetFromOrigin(ui::GetWidgetScreenOffset(widget)); } else { + gint x, y; gtk_widget_translate_coordinates(widget, GTK_WIDGET(window), 0, 0, &x, &y); + origin = gfx::Point(x, y); } - bounds->set_origin(gfx::Point(x, y)); + bounds->set_origin(origin); } } diff --git a/chrome/browser/notifications/balloon.h b/chrome/browser/notifications/balloon.h index e03f8d2..165b51b 100644 --- a/chrome/browser/notifications/balloon.h +++ b/chrome/browser/notifications/balloon.h @@ -63,9 +63,9 @@ class Balloon { } void SetPosition(const gfx::Point& upper_left, bool reposition); - const gfx::Point& offset() { return offset_;} - void set_offset(const gfx::Point& offset) { offset_ = offset; } - void add_offset(const gfx::Point& offset) { offset_ = offset_.Add(offset); } + const gfx::Vector2d& offset() const { return offset_; } + void set_offset(const gfx::Vector2d& offset) { offset_ = offset; } + void add_offset(const gfx::Vector2d& offset) { offset_.Add(offset); } const gfx::Size& content_size() const { return content_size_; } void set_content_size(const gfx::Size& size) { content_size_ = size; } @@ -126,7 +126,7 @@ class Balloon { // Temporary offset for balloons that need to be positioned in a non-standard // position for keeping the close buttons under the mouse cursor. - gfx::Point offset_; + gfx::Vector2d offset_; // Smallest size for this balloon where scrollbars will be shown. gfx::Size min_scrollbar_size_; diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc index 4057eef..541c12b 100644 --- a/chrome/browser/notifications/balloon_collection_impl.cc +++ b/chrome/browser/notifications/balloon_collection_impl.cc @@ -137,7 +137,7 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) { Balloons::const_iterator it = balloons.begin(); if (layout_.RequiresOffsets()) { - gfx::Point offset; + gfx::Vector2d offset; bool apply_offset = false; while (it != balloons.end()) { if (*it == source) { @@ -249,7 +249,7 @@ void BalloonCollectionImpl::CancelOffsets() { for (Balloons::const_iterator it = balloons.begin(); it != balloons.end(); ++it) - (*it)->set_offset(gfx::Point(0, 0)); + (*it)->set_offset(gfx::Vector2d()); PositionBalloons(true); } diff --git a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc index f995bac..3b1b912 100644 --- a/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc +++ b/chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc @@ -1176,8 +1176,8 @@ void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, gtk_widget_size_request(drag_icon_, &req); gfx::Rect button_rect = gtk_util::WidgetBounds(button); gfx::Point drag_icon_relative = - gfx::Rect(req.width, req.height).CenterPoint().Add( - (last_pressed_coordinates_.Subtract(button_rect.CenterPoint()))); + gfx::Rect(req.width, req.height).CenterPoint() + + (last_pressed_coordinates_ - button_rect.CenterPoint()); gtk_drag_set_icon_widget(drag_context, drag_icon_, drag_icon_relative.x(), drag_icon_relative.y()); diff --git a/chrome/browser/ui/gtk/download/download_shelf_gtk.cc b/chrome/browser/ui/gtk/download/download_shelf_gtk.cc index 054a9dc..662a79f 100644 --- a/chrome/browser/ui/gtk/download/download_shelf_gtk.cc +++ b/chrome/browser/ui/gtk/download/download_shelf_gtk.cc @@ -383,11 +383,7 @@ bool DownloadShelfGtk::IsCursorInShelfZone( if (!realized) return false; - GtkAllocation allocation; - gtk_widget_get_allocation(shelf_.get(), &allocation); - - gfx::Rect bounds(ui::GetWidgetScreenPosition(shelf_.get()), - gfx::Size(allocation.width, allocation.height)); + gfx::Rect bounds = ui::GetWidgetScreenBounds(shelf_.get()); // Negative insets expand the rectangle. We only expand the top. bounds.Inset(gfx::Insets(-kShelfAuraSize, 0, 0, 0)); diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc index 1517934..a74ebb7 100644 --- a/chrome/browser/ui/gtk/gtk_util.cc +++ b/chrome/browser/ui/gtk/gtk_util.cc @@ -484,8 +484,7 @@ void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) { DCHECK(widget); DCHECK(p); - gfx::Point position = ui::GetWidgetScreenPosition(widget); - p->SetPoint(p->x() + position.x(), p->y() + position.y()); + *p = p->Add(ui::GetWidgetScreenOffset(widget)); } GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget, diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc index d3d14db..cd65155 100644 --- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc @@ -506,9 +506,7 @@ void DraggedTabControllerGtk::Detach() { gfx::Point DraggedTabControllerGtk::ConvertScreenPointToTabStripPoint( TabStripGtk* tabstrip, const gfx::Point& screen_point) { - gfx::Point tabstrip_screen_point = - ui::GetWidgetScreenPosition(tabstrip->tabstrip_.get()); - return screen_point.Subtract(tabstrip_screen_point); + return screen_point - ui::GetWidgetScreenOffset(tabstrip->tabstrip_.get()); } gfx::Rect DraggedTabControllerGtk::GetDraggedViewTabStripBounds( @@ -818,8 +816,7 @@ gfx::Rect DraggedTabControllerGtk::GetAnimateBounds() { gfx::Rect bounds = tab->GetRequisition(); GtkWidget* widget = tab->widget(); GtkWidget* parent = gtk_widget_get_parent(widget); - gfx::Point point = ui::GetWidgetScreenPosition(parent); - bounds.Offset(point); + bounds.Offset(ui::GetWidgetScreenOffset(parent)); return gfx::Rect(bounds.x(), bounds.y(), dragged_view_->GetTotalWidthInTabStrip(), bounds.height()); diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc index 5c7ed88..f5dff68 100644 --- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc @@ -99,15 +99,9 @@ const int kCloseButtonHorzFuzz = 4; // Gets the bounds of |widget| relative to |parent|. gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent, GtkWidget* widget) { - gfx::Point parent_pos = ui::GetWidgetScreenPosition(parent); - gfx::Point widget_pos = ui::GetWidgetScreenPosition(widget); - - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - - return gfx::Rect(widget_pos.x() - parent_pos.x(), - widget_pos.y() - parent_pos.y(), - allocation.width, allocation.height); + gfx::Rect bounds = ui::GetWidgetScreenBounds(widget); + bounds.Offset(-ui::GetWidgetScreenOffset(parent)); + return bounds; } // Returns a GdkPixbuf after resizing the SkBitmap as necessary. Caller must diff --git a/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc b/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc index 7db8886..026f95c 100644 --- a/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc +++ b/chrome/browser/ui/panels/panel_and_desktop_notification_browsertest.cc @@ -101,7 +101,7 @@ class PanelAndDesktopNotificationTest : public BasePanelBrowserTest { static void ResizePanelByMouseWithDelta(Panel* panel, panel::ResizingSides side, - const gfx::Point& delta) { + const gfx::Vector2d& delta) { PanelManager* panel_manager = PanelManager::GetInstance(); gfx::Point mouse_location = panel->GetBounds().origin(); panel_manager->StartResizingByMouse(panel, mouse_location, side); @@ -308,7 +308,7 @@ IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, ResizePanelByMouse) { // Resize the panel to make it taller. Expect that the notification balloon // moves further up by the amount of enlarge offset. - gfx::Point drag_delta(-50, -100); + gfx::Vector2d drag_delta(-50, -100); ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP_LEFT, drag_delta); MessageLoopForUI::current()->RunAllPending(); int balloon_bottom2 = GetBalloonBottomPosition(balloon); @@ -316,7 +316,7 @@ IN_PROC_BROWSER_TEST_F(PanelAndDesktopNotificationTest, ResizePanelByMouse) { // Resize the panel to make it shorter. Expect that the notification balloon // moves down by the amount of shrink offset. - drag_delta = gfx::Point(0, 60); + drag_delta = gfx::Vector2d(0, 60); ResizePanelByMouseWithDelta(panel, panel::RESIZE_TOP, drag_delta); MessageLoopForUI::current()->RunAllPending(); int balloon_bottom3 = GetBalloonBottomPosition(balloon); diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index bc8fd20..cdb3573 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -513,7 +513,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AnimateBounds) { // dragged. gfx::Point mouse_location(panel->GetBounds().origin()); panel_testing->PressLeftMouseButtonTitlebar(mouse_location); - panel_testing->DragTitlebar(mouse_location.Add(gfx::Point(-100, 5))); + panel_testing->DragTitlebar(mouse_location.Add(gfx::Vector2d(-100, 5))); EXPECT_FALSE(panel_testing->IsAnimatingBounds()); panel_testing->FinishDragTitlebar(); diff --git a/chrome/browser/ui/panels/panel_drag_browsertest.cc b/chrome/browser/ui/panels/panel_drag_browsertest.cc index 6bc24c5..e053aeb 100644 --- a/chrome/browser/ui/panels/panel_drag_browsertest.cc +++ b/chrome/browser/ui/panels/panel_drag_browsertest.cc @@ -35,7 +35,7 @@ class PanelDragBrowserTest : public BasePanelBrowserTest { } // Drag |panel| from its origin by the offset |delta|. - void DragPanelByDelta(Panel* panel, const gfx::Point& delta) { + void DragPanelByDelta(Panel* panel, const gfx::Vector2d& delta) { scoped_ptr<NativePanelTesting> panel_testing( CreateNativePanelTesting(panel)); gfx::Point mouse_location(panel->GetBounds().origin()); @@ -55,30 +55,30 @@ class PanelDragBrowserTest : public BasePanelBrowserTest { panel_testing->FinishDragTitlebar(); } - static gfx::Point GetDragDeltaToRemainDocked() { - return gfx::Point( + static gfx::Vector2d GetDragDeltaToRemainDocked() { + return gfx::Vector2d( -5, -(PanelDragController::GetDetachDockedPanelThreshold() / 2)); } - static gfx::Point GetDragDeltaToDetach() { - return gfx::Point( + static gfx::Vector2d GetDragDeltaToDetach() { + return gfx::Vector2d( -20, -(PanelDragController::GetDetachDockedPanelThreshold() + 20)); } - static gfx::Point GetDragDeltaToRemainDetached(Panel* panel) { + static gfx::Vector2d GetDragDeltaToRemainDetached(Panel* panel) { int distance = panel->manager()->docked_strip()->display_area().bottom() - panel->GetBounds().bottom(); - return gfx::Point( + return gfx::Vector2d( -5, distance - PanelDragController::GetDockDetachedPanelThreshold() * 2); } - static gfx::Point GetDragDeltaToAttach(Panel* panel) { + static gfx::Vector2d GetDragDeltaToAttach(Panel* panel) { int distance = panel->manager()->docked_strip()->display_area().bottom() - panel->GetBounds().bottom(); - return gfx::Point( + return gfx::Vector2d( -20, distance - PanelDragController::GetDockDetachedPanelThreshold() / 2); } @@ -177,7 +177,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragOneDockedPanel) { } IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { - static const gfx::Point small_delta(10, 0); + static const gfx::Vector2d small_delta(10, 0); Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 100, 100)); Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 100, 100)); @@ -211,7 +211,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position2, panel2->GetBounds().origin()); - mouse_location = position2.Add(gfx::Point(1, 0)); + mouse_location = position2.Add(gfx::Vector2d(1, 0)); panel1_testing->DragTitlebar(mouse_location); EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); EXPECT_EQ(position1, panel2->GetBounds().origin()); @@ -243,7 +243,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { EXPECT_EQ(position2, panel1->GetBounds().origin()); EXPECT_EQ(position1, panel2->GetBounds().origin()); - mouse_location = position1.Add(gfx::Point(1, 0)); + mouse_location = position1.Add(gfx::Vector2d(1, 0)); panel1_testing->DragTitlebar(mouse_location); EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); EXPECT_EQ(position2, panel2->GetBounds().origin()); @@ -260,7 +260,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragTwoDockedPanels) { EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position2, panel2->GetBounds().origin()); - mouse_location = position2.Add(gfx::Point(1, 0)); + mouse_location = position2.Add(gfx::Vector2d(1, 0)); panel1_testing->DragTitlebar(mouse_location); EXPECT_EQ(mouse_location, panel1->GetBounds().origin()); EXPECT_EQ(position1, panel2->GetBounds().origin()); @@ -294,13 +294,13 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { EXPECT_EQ(position2, panel2->GetBounds().origin()); EXPECT_EQ(position3, panel3->GetBounds().origin()); - mouse_location = position2.Add(gfx::Point(1, 0)); + mouse_location = position2.Add(gfx::Vector2d(1, 0)); panel3_testing->DragTitlebar(mouse_location); EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position3, panel2->GetBounds().origin()); EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); - mouse_location = position1.Add(gfx::Point(1, 0)); + mouse_location = position1.Add(gfx::Vector2d(1, 0)); panel3_testing->DragTitlebar(mouse_location); EXPECT_EQ(position2, panel1->GetBounds().origin()); EXPECT_EQ(position3, panel2->GetBounds().origin()); @@ -323,13 +323,13 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { EXPECT_EQ(position3, panel2->GetBounds().origin()); EXPECT_EQ(position1, panel3->GetBounds().origin()); - mouse_location = position2.Add(gfx::Point(1, 0)); + mouse_location = position2.Add(gfx::Vector2d(1, 0)); panel3_testing->DragTitlebar(mouse_location); EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position3, panel2->GetBounds().origin()); EXPECT_EQ(mouse_location, panel3->GetBounds().origin()); - mouse_location = position3.Add(gfx::Point(1, 0)); + mouse_location = position3.Add(gfx::Vector2d(1, 0)); panel3_testing->DragTitlebar(mouse_location); EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position2, panel2->GetBounds().origin()); @@ -349,7 +349,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { EXPECT_EQ(position3, panel2->GetBounds().origin()); EXPECT_EQ(position1, panel3->GetBounds().origin()); - mouse_location = position1.Add(gfx::Point(1, 0)); + mouse_location = position1.Add(gfx::Vector2d(1, 0)); panel2_testing->DragTitlebar(mouse_location); EXPECT_EQ(position3, panel1->GetBounds().origin()); EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); @@ -369,7 +369,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { EXPECT_EQ(position1, panel2->GetBounds().origin()); EXPECT_EQ(position2, panel3->GetBounds().origin()); - mouse_location = position3.Add(gfx::Point(1, 0)); + mouse_location = position3.Add(gfx::Vector2d(1, 0)); panel2_testing->DragTitlebar(mouse_location); EXPECT_EQ(position2, panel1->GetBounds().origin()); EXPECT_EQ(mouse_location, panel2->GetBounds().origin()); @@ -391,7 +391,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DragThreeDockedPanels) { EXPECT_EQ(position3, panel2->GetBounds().origin()); EXPECT_EQ(position1, panel3->GetBounds().origin()); - mouse_location = position3.Add(gfx::Point(1, 0)); + mouse_location = position3.Add(gfx::Vector2d(1, 0)); panel3_testing->DragTitlebar(mouse_location); EXPECT_EQ(position1, panel1->GetBounds().origin()); EXPECT_EQ(position2, panel2->GetBounds().origin()); @@ -862,7 +862,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) { // Drag up the panel in a small offset that does not trigger the detach. // Expect that the panel is still docked and only x coordinate of its position // is changed. - gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); + gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); mouse_location = mouse_location.Add(drag_delta_to_remain_docked); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(1, docked_strip->num_panels()); @@ -874,7 +874,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Detach) { // Continue dragging up the panel in big offset that triggers the detach. // Expect that the panel is previewed as detached. - gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); + gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); mouse_location = mouse_location.Add(drag_delta_to_detach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(0, docked_strip->num_panels()); @@ -917,7 +917,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndCancel) { // Drag up the panel in a small offset that does not trigger the detach. // Expect that the panel is still docked and only x coordinate of its position // is changed. - gfx::Point drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); + gfx::Vector2d drag_delta_to_remain_docked = GetDragDeltaToRemainDocked(); mouse_location = mouse_location.Add(drag_delta_to_remain_docked); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(1, docked_strip->num_panels()); @@ -929,7 +929,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAndCancel) { // Continue dragging up the panel in big offset that triggers the detach. // Expect that the panel is previewed as detached. - gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); + gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); mouse_location = mouse_location.Add(drag_delta_to_detach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(0, docked_strip->num_panels()); @@ -972,7 +972,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Attach) { // Drag down the panel but not close enough to the bottom of work area. // Expect that the panel is still detached. - gfx::Point drag_delta_to_remain_detached = + gfx::Vector2d drag_delta_to_remain_detached = GetDragDeltaToRemainDetached(panel); mouse_location = mouse_location.Add(drag_delta_to_remain_detached); panel_testing->DragTitlebar(mouse_location); @@ -986,7 +986,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, Attach) { // Continue dragging down the panel to make it close enough to the bottom of // work area. // Expect that the panel is previewed as docked. - gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); + gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel); mouse_location = mouse_location.Add(drag_delta_to_attach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(1, docked_strip->num_panels()); @@ -1031,7 +1031,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachAndCancel) { // Drag down the panel but not close enough to the bottom of work area. // Expect that the panel is still detached. - gfx::Point drag_delta_to_remain_detached = + gfx::Vector2d drag_delta_to_remain_detached = GetDragDeltaToRemainDetached(panel); mouse_location = mouse_location.Add(drag_delta_to_remain_detached); panel_testing->DragTitlebar(mouse_location); @@ -1045,7 +1045,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, AttachAndCancel) { // Continue dragging down the panel to make it close enough to the bottom of // work area. // Expect that the panel is previewed as docked. - gfx::Point drag_delta_to_attach = GetDragDeltaToAttach(panel); + gfx::Vector2d drag_delta_to_attach = GetDragDeltaToAttach(panel); mouse_location = mouse_location.Add(drag_delta_to_attach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(1, docked_strip->num_panels()); @@ -1085,7 +1085,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { // Drag up the panel to trigger the detach. // Expect that the panel is previewed as detached. - gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); + gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); mouse_location = mouse_location.Add(drag_delta_to_detach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(0, docked_strip->num_panels()); @@ -1096,7 +1096,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { EXPECT_EQ(panel_new_bounds, panel->GetBounds()); // Continue dragging down the panel to trigger the re-attach. - gfx::Point drag_delta_to_reattach = GetDragDeltaToAttach(panel); + gfx::Vector2d drag_delta_to_reattach = GetDragDeltaToAttach(panel); mouse_location = mouse_location.Add(drag_delta_to_reattach); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(1, docked_strip->num_panels()); @@ -1106,7 +1106,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachAttachAndCancel) { EXPECT_EQ(panel_new_bounds, panel->GetBounds()); // Continue dragging up the panel to trigger the detach again. - gfx::Point drag_delta_to_detach_again = GetDragDeltaToDetach(); + gfx::Vector2d drag_delta_to_detach_again = GetDragDeltaToDetach(); mouse_location = mouse_location.Add(drag_delta_to_detach_again); panel_testing->DragTitlebar(mouse_location); ASSERT_EQ(0, docked_strip->num_panels()); @@ -1131,7 +1131,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, DetachWithSqueeze) { DockedPanelStrip* docked_strip = panel_manager->docked_strip(); DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); - gfx::Point drag_delta_to_detach = GetDragDeltaToDetach(); + gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); // Create some docked panels. // docked: P1 P2 P3 P4 P5 diff --git a/chrome/browser/ui/panels/panel_drag_controller.cc b/chrome/browser/ui/panels/panel_drag_controller.cc index 0919bf3..37c6848 100644 --- a/chrome/browser/ui/panels/panel_drag_controller.cc +++ b/chrome/browser/ui/panels/panel_drag_controller.cc @@ -36,7 +36,7 @@ void PanelDragController::StartDragging(Panel* panel, last_mouse_location_ = mouse_location; offset_from_mouse_location_on_drag_start_ = - mouse_location.Subtract(panel->GetBounds().origin()); + mouse_location - panel->GetBounds().origin(); dragging_panel_ = panel; dragging_panel_->SetPreviewMode(true); diff --git a/chrome/browser/ui/panels/panel_drag_controller.h b/chrome/browser/ui/panels/panel_drag_controller.h index 75a30e9..5128fd1 100644 --- a/chrome/browser/ui/panels/panel_drag_controller.h +++ b/chrome/browser/ui/panels/panel_drag_controller.h @@ -76,7 +76,7 @@ class PanelDragController { // The offset from mouse location to the panel position when the drag // starts. - gfx::Point offset_from_mouse_location_on_drag_start_; + gfx::Vector2d offset_from_mouse_location_on_drag_start_; // The minimum distance that the docked panel gets dragged up in order to // make it free-floating. diff --git a/chrome/browser/ui/panels/panel_resize_browsertest.cc b/chrome/browser/ui/panels/panel_resize_browsertest.cc index 7ca7ea3..9d39794 100644 --- a/chrome/browser/ui/panels/panel_resize_browsertest.cc +++ b/chrome/browser/ui/panels/panel_resize_browsertest.cc @@ -52,7 +52,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the top. - mouse_location = bounds.origin().Add(gfx::Point(10, 1)); + mouse_location = bounds.origin().Add(gfx::Vector2d(10, 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_TOP); mouse_location.Offset(5, -10); @@ -66,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the left side. - mouse_location = bounds.origin().Add(gfx::Point(1, 30)); + mouse_location = bounds.origin().Add(gfx::Vector2d(1, 30)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_LEFT); mouse_location.Offset(-5, 25); @@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the top right side. - mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 2)); + mouse_location = bounds.origin().Add(gfx::Vector2d(bounds.width() - 1, 2)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_TOP_RIGHT); mouse_location.Offset(30, 20); @@ -96,7 +96,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the right side. - mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 30)); + mouse_location = bounds.origin().Add(gfx::Vector2d(bounds.width() - 1, 30)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_RIGHT); mouse_location.Offset(5, 25); @@ -111,7 +111,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the bottom side; verify resize won't work. - mouse_location = bounds.origin().Add(gfx::Point(10, bounds.height() - 1)); + mouse_location = bounds.origin().Add(gfx::Vector2d(10, bounds.height() - 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM); mouse_location.Offset(30, -10); @@ -122,7 +122,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the bottom left corner; verify resize won't work. - mouse_location = bounds.origin().Add(gfx::Point(1, bounds.height() - 1)); + mouse_location = bounds.origin().Add(gfx::Vector2d(1, bounds.height() - 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM_LEFT); mouse_location.Offset(-10, 15); @@ -134,7 +134,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { // Try resizing by the bottom right corner; verify resize won't work. mouse_location = bounds.origin().Add( - gfx::Point(bounds.width() - 2, bounds.height())); + gfx::Vector2d(bounds.width() - 2, bounds.height())); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM_RIGHT); mouse_location.Offset(20, 10); @@ -157,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { // Try resizing by the right side; verify resize will change width only. gfx::Point mouse_location = bounds.origin().Add( - gfx::Point(bounds.width() - 1, 30)); + gfx::Vector2d(bounds.width() - 1, 30)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_RIGHT); mouse_location.Offset(5, 25); @@ -170,7 +170,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the bottom left side. - mouse_location = bounds.origin().Add(gfx::Point(1, bounds.height() - 1)); + mouse_location = bounds.origin().Add(gfx::Vector2d(1, bounds.height() - 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM_LEFT); mouse_location.Offset(-10, 15); @@ -184,7 +184,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the top right side. - mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 2)); + mouse_location = bounds.origin().Add(gfx::Vector2d(bounds.width() - 1, 2)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_TOP_RIGHT); mouse_location.Offset(30, 20); @@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { EXPECT_EQ(bounds, panel->GetBounds()); // Try resizing by the top left side. - mouse_location = bounds.origin().Add(gfx::Point(1, 0)); + mouse_location = bounds.origin().Add(gfx::Vector2d(1, 0)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_TOP_LEFT); mouse_location.Offset(-20, -10); @@ -224,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) { // Make sure the panel does not resize smaller than its min size. gfx::Point mouse_location = bounds.origin().Add( - gfx::Point(30, bounds.height() - 2)); + gfx::Vector2d(30, bounds.height() - 2)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM); mouse_location.Offset(-20, -500); @@ -238,7 +238,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) { // Make sure the panel can resize larger than its size. User is in control. mouse_location = bounds.origin().Add( - gfx::Point(bounds.width(), bounds.height() - 2)); + gfx::Vector2d(bounds.width(), bounds.height() - 2)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM_RIGHT); @@ -277,7 +277,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, CloseDetachedPanelOnResize) { // Start resizing panel1, and close panel2 in the process. // Panel1 is not affected. gfx::Point mouse_location = panel1_bounds.origin().Add( - gfx::Point(1, panel1_bounds.height() - 1)); + gfx::Vector2d(1, panel1_bounds.height() - 1)); panel_manager->StartResizingByMouse(panel1, mouse_location, panel::RESIZE_BOTTOM_LEFT); mouse_location.Offset(-10, 15); @@ -298,7 +298,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, CloseDetachedPanelOnResize) { // Start resizing panel3, and close it in the process. // Resize should abort, panel1 will not be affected. mouse_location = panel3_bounds.origin().Add( - gfx::Point(panel3_bounds.width() - 1, panel3_bounds.height() - 2)); + gfx::Vector2d(panel3_bounds.width() - 1, panel3_bounds.height() - 2)); panel_manager->StartResizingByMouse(panel3, mouse_location, panel::RESIZE_BOTTOM_RIGHT); mouse_location.Offset(7, -12); @@ -334,7 +334,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeAndCancel) { // Try resizing by the top right side. gfx::Rect bounds = panel->GetBounds(); gfx::Point mouse_location = bounds.origin().Add( - gfx::Point(bounds.width() - 1, 1)); + gfx::Vector2d(bounds.width() - 1, 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_TOP_RIGHT); mouse_location.Offset(5, 25); @@ -350,7 +350,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeAndCancel) { // Try resizing by the bottom left side. bounds = panel->GetBounds(); mouse_location = bounds.origin().Add( - gfx::Point(1, bounds.height() - 1)); + gfx::Vector2d(1, bounds.height() - 1)); panel_manager->StartResizingByMouse(panel, mouse_location, panel::RESIZE_BOTTOM_LEFT); mouse_location.Offset(-10, 15); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 9cb0fa4..2811a56 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -1005,7 +1005,8 @@ void BookmarkBarView::WriteDragDataForView(View* sender, scoped_ptr<gfx::Canvas> canvas( views::GetCanvasForDragImage(button->GetWidget(), button->size())); button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); - drag_utils::SetDragImageOnDataObject(*canvas, button->size(), press_pt, + drag_utils::SetDragImageOnDataObject(*canvas, button->size(), + press_pt.OffsetFromOrigin(), data); WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); return; @@ -1041,8 +1042,9 @@ bool BookmarkBarView::CanStartDragForView(views::View* sender, const gfx::Point& p) { // Check if we have not moved enough horizontally but we have moved downward // vertically - downward drag. - if (!View::ExceededDragThreshold(press_pt.x() - p.x(), 0) && - press_pt.y() < p.y()) { + gfx::Vector2d move_offset = p - press_pt; + gfx::Vector2d horizontal_offset(move_offset.x(), 0); + if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { for (int i = 0; i < GetBookmarkButtonCount(); ++i) { if (sender == GetBookmarkButton(i)) { const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); diff --git a/chrome/browser/ui/views/browser_actions_container.cc b/chrome/browser/ui/views/browser_actions_container.cc index 721c14e..18937d5 100644 --- a/chrome/browser/ui/views/browser_actions_container.cc +++ b/chrome/browser/ui/views/browser_actions_container.cc @@ -389,7 +389,8 @@ void BrowserActionsContainer::WriteDragDataForView(View* sender, if (button == sender) { // Set the dragging image for the icon. gfx::ImageSkia badge(browser_action_views_[i]->GetIconWithBadge()); - drag_utils::SetDragImageOnDataObject(badge, button->size(), press_pt, + drag_utils::SetDragImageOnDataObject(badge, button->size(), + press_pt.OffsetFromOrigin(), data); // Fill in the remaining info. diff --git a/chrome/browser/ui/views/constrained_window_views.cc b/chrome/browser/ui/views/constrained_window_views.cc index 3b4ae1a6..4e26cc5 100644 --- a/chrome/browser/ui/views/constrained_window_views.cc +++ b/chrome/browser/ui/views/constrained_window_views.cc @@ -751,5 +751,5 @@ void ConstrainedWindowViews::PositionChromeStyleWindow(const gfx::Size& size) { return; } - SetBounds(gfx::Rect(point - gfx::Point(size.width() / 2, 0), size)); + SetBounds(gfx::Rect(point - gfx::Vector2d(size.width() / 2, 0), size)); } diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 34696e8..138f7ea 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -426,9 +426,7 @@ bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { widget ? widget->GetNativeView() : NULL); } } - } else if (ExceededDragThreshold( - event.location().x() - drag_start_point_.x(), - event.location().y() - drag_start_point_.y())) { + } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { dragging_ = true; } return true; @@ -676,7 +674,7 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) { // (hot_)body_image_set->bottom_left, and drop_down_image_set, // for RTL UI, we flip the canvas to draw those images mirrored. // Consequently, we do not need to mirror the x-axis of those images. - canvas->Translate(gfx::Point(width(), 0)); + canvas->Translate(gfx::Vector2d(width(), 0)); canvas->Scale(-1, 1); } PaintImages(canvas, diff --git a/chrome/browser/ui/views/dropdown_bar_view.cc b/chrome/browser/ui/views/dropdown_bar_view.cc index d7e8b39..dcd5567 100644 --- a/chrome/browser/ui/views/dropdown_bar_view.cc +++ b/chrome/browser/ui/views/dropdown_bar_view.cc @@ -114,7 +114,7 @@ void DropdownBarView::OnPaint(gfx::Canvas* canvas) { gfx::Size(bounds().width(), kAnimatingEdgeHeight), canvas->scale_factor(), false); - canvas->Translate(bounds().origin()); + canvas->Translate(bounds().OffsetFromOrigin()); OnPaintBackground(&animating_edges); OnPaintBorder(&animating_edges); canvas->DrawImageInt(gfx::ImageSkia(animating_edges.ExtractImageRep()), diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index ca39384..e77f32e 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -458,7 +458,8 @@ gfx::Point BrowserView::OffsetPointForToolbarBackgroundImage( // The background image starts tiling horizontally at the window left edge and // vertically at the top edge of the horizontal tab strip (or where it would // be). We expect our parent's origin to be the window origin. - gfx::Point window_point(point.Add(GetMirroredPosition())); + gfx::Point window_point( + point.Add(GetMirroredPosition().OffsetFromOrigin())); window_point.Offset(frame_->GetThemeBackgroundXInset(), -frame_->GetTabStripInsets(false).top); return window_point; diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index 62b4c97..85aaae4 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -121,8 +121,8 @@ struct AutocompleteEditState : public base::SupportsUserData::Data { // Returns true if the current point is far enough from the origin that it // would be considered a drag. bool IsDrag(const POINT& origin, const POINT& current) { - return views::View::ExceededDragThreshold(current.x - origin.x, - current.y - origin.y); + return views::View::ExceededDragThreshold( + gfx::Point(current) - gfx::Point(origin)); } // Write |text| and an optional |url| to the clipboard. diff --git a/chrome/browser/ui/views/panels/panel_view.cc b/chrome/browser/ui/views/panels/panel_view.cc index 37dc227..7238b69 100644 --- a/chrome/browser/ui/views/panels/panel_view.cc +++ b/chrome/browser/ui/views/panels/panel_view.cc @@ -767,10 +767,8 @@ bool PanelView::OnTitlebarMouseDragged(const gfx::Point& mouse_location) { if (!mouse_pressed_) return false; - int delta_x = mouse_location.x() - last_mouse_location_.x(); - int delta_y = mouse_location.y() - last_mouse_location_.y(); if (mouse_dragging_state_ == NO_DRAGGING && - ExceededDragThreshold(delta_x, delta_y)) { + ExceededDragThreshold(mouse_location - last_mouse_location_)) { // When a drag begins, we do not want to the client area to still receive // the focus. We do not need to do this for the unfocused minimized panel. if (!panel_->IsMinimized()) { diff --git a/chrome/browser/ui/views/speech_recognition_bubble_views.cc b/chrome/browser/ui/views/speech_recognition_bubble_views.cc index 40e7fc9..249ee77 100644 --- a/chrome/browser/ui/views/speech_recognition_bubble_views.cc +++ b/chrome/browser/ui/views/speech_recognition_bubble_views.cc @@ -128,7 +128,7 @@ gfx::Rect SpeechRecognitionBubbleView::GetAnchorRect() { gfx::Rect container_rect; web_contents_->GetContainerBounds(&container_rect); gfx::Rect anchor(element_rect_); - anchor.Offset(container_rect.origin()); + anchor.Offset(container_rect.OffsetFromOrigin()); if (!container_rect.Intersects(anchor)) return BubbleDelegateView::GetAnchorRect(); return anchor; diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc index 146fa9b..c4af459f 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc @@ -112,7 +112,7 @@ class DockView : public views::View { bool rtl_ui = base::i18n::IsRTL(); if (rtl_ui) { // Flip canvas to draw the mirrored tab images for RTL UI. - canvas->Translate(gfx::Point(width(), 0)); + canvas->Translate(gfx::Vector2d(width(), 0)); canvas->Scale(-1, 1); } int x_of_active_tab = width() / 2 + kTabSpacing / 2; @@ -504,8 +504,7 @@ void TabDragController::Drag(const gfx::Point& point_in_screen) { Attach(source_tabstrip_, gfx::Point()); if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == GetModel(source_tabstrip_)->count()) { - gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); - RunMoveLoop(dragged_view_point); + RunMoveLoop(GetWindowOffset(point_in_screen)); return; } } @@ -1305,8 +1304,7 @@ void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( // All the tabs in a browser are being dragged but all the tabs weren't // initially being dragged. For this to happen the user would have to // start dragging a set of tabs, the other tabs close, then detach. - gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); - RunMoveLoop(dragged_view_point); + RunMoveLoop(GetWindowOffset(point_in_screen)); return; } @@ -1320,7 +1318,7 @@ void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(attached_point.x()); - gfx::Point drag_offset; + gfx::Vector2d drag_offset; Browser* browser = CreateBrowserForDrag( attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); Detach(DONT_RELEASE_CAPTURE); @@ -1343,7 +1341,7 @@ void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( RunMoveLoop(drag_offset); } -void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { +void TabDragController::RunMoveLoop(const gfx::Vector2d& drag_offset) { // If the user drags the whole window we'll assume they are going to attach to // another window and therefor want to reorder. move_behavior_ = REORDER; @@ -1979,7 +1977,7 @@ bool TabDragController::AreTabsConsecutive() { Browser* TabDragController::CreateBrowserForDrag( TabStrip* source, const gfx::Point& point_in_screen, - gfx::Point* drag_offset, + gfx::Vector2d* drag_offset, std::vector<gfx::Rect>* drag_bounds) { gfx::Point center(0, source->height() / 2); views::View::ConvertPointToWidget(source, ¢er); @@ -2006,7 +2004,7 @@ Browser* TabDragController::CreateBrowserForDrag( break; // Nothing to do for DETACH_ABOVE_OR_BELOW. } - *drag_offset = point_in_screen.Subtract(new_bounds.origin()); + *drag_offset = point_in_screen - new_bounds.origin(); Browser::CreateParams create_params( Browser::TYPE_TABBED, @@ -2040,13 +2038,13 @@ gfx::Point TabDragController::GetCursorScreenPoint() { return screen_->GetCursorScreenPoint(); } -gfx::Point TabDragController::GetWindowOffset( +gfx::Vector2d TabDragController::GetWindowOffset( const gfx::Point& point_in_screen) { TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? attached_tabstrip_ : source_tabstrip_; views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); - gfx::Point offset = point_in_screen; - views::View::ConvertPointFromScreen(toplevel_view, &offset); - return offset; + gfx::Point point = point_in_screen; + views::View::ConvertPointFromScreen(toplevel_view, &point); + return point.OffsetFromOrigin(); } diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.h b/chrome/browser/ui/views/tabs/tab_drag_controller.h index bee1341f..fd68891 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.h +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.h @@ -335,7 +335,7 @@ class TabDragController : public content::WebContentsDelegate, // Browser. |drag_offset| is the offset from the window origin and is used in // calculating the location of the window offset from the cursor while // dragging. - void RunMoveLoop(const gfx::Point& drag_offset); + void RunMoveLoop(const gfx::Vector2d& drag_offset); // Determines the index to insert tabs at. |dragged_bounds| is the bounds of // the tabs being dragged, |start| the index of the tab to start looking from @@ -442,7 +442,7 @@ class TabDragController : public content::WebContentsDelegate, // Creates and returns a new Browser to handle the drag. Browser* CreateBrowserForDrag(TabStrip* source, const gfx::Point& point_in_screen, - gfx::Point* drag_offset, + gfx::Vector2d* drag_offset, std::vector<gfx::Rect>* drag_bounds); // Returns the TabStripModel for the specified tabstrip. @@ -454,7 +454,7 @@ class TabDragController : public content::WebContentsDelegate, // Returns the offset from the top left corner of the window to // |point_in_screen|. - gfx::Point GetWindowOffset(const gfx::Point& point_in_screen); + gfx::Vector2d GetWindowOffset(const gfx::Point& point_in_screen); // Returns true if moving the mouse only changes the visible tabs. bool move_only() const { diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc index a2309a2..f7164c7 100644 --- a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc +++ b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc @@ -25,8 +25,7 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, // When not in compact mode we must take into account the window's position on // the desktop. - read_pixels_bounds.set_origin( - snapshot_bounds.origin().Add(window->bounds().origin())); + read_pixels_bounds.Offset(window->bounds().OffsetFromOrigin()); gfx::Rect read_pixels_bounds_in_pixel = ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm index d52ddac..be34972 100644 --- a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm +++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm @@ -27,9 +27,8 @@ bool GrabWindowSnapshot(gfx::NativeWindow window, // Convert snapshot bounds relative to window into bounds relative to // screen. - gfx::Rect screen_snapshot_bounds = gfx::Rect( - window_bounds.origin().Add(snapshot_bounds.origin()), - snapshot_bounds.size()); + gfx::Rect screen_snapshot_bounds = snapshot_bounds; + screen_snapshot_bounds.Offset(window_bounds.OffsetFromOrigin()); DCHECK_LE(screen_snapshot_bounds.right(), window_bounds.right()); DCHECK_LE(screen_snapshot_bounds.bottom(), window_bounds.bottom()); diff --git a/content/browser/accessibility/browser_accessibility.cc b/content/browser/accessibility/browser_accessibility.cc index c87abb0..857a161 100644 --- a/content/browser/accessibility/browser_accessibility.cc +++ b/content/browser/accessibility/browser_accessibility.cc @@ -151,8 +151,7 @@ gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() { // Adjust the bounds by the top left corner of the containing view's bounds // in screen coordinates. - gfx::Point top_left = manager_->GetViewBounds().origin(); - bounds.Offset(top_left); + bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); return bounds; } diff --git a/content/browser/accessibility/browser_accessibility_win.cc b/content/browser/accessibility/browser_accessibility_win.cc index 5696ce2..71d8908 100644 --- a/content/browser/accessibility/browser_accessibility_win.cc +++ b/content/browser/accessibility/browser_accessibility_win.cc @@ -790,22 +790,18 @@ STDMETHODIMP BrowserAccessibilityWin::scrollToPoint( if (!instance_active_) return E_FAIL; + gfx::Point scroll_to(x, y); + if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { - gfx::Point top_left = manager_->GetViewBounds().origin(); - x -= top_left.x(); - y -= top_left.y(); + scroll_to -= manager_->GetViewBounds().OffsetFromOrigin(); } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { - if (parent_) { - gfx::Rect parent_bounds = parent_->location(); - x += parent_bounds.x(); - y += parent_bounds.y(); - } + if (parent_) + scroll_to += parent_->location().OffsetFromOrigin(); } else { return E_INVALIDARG; } - gfx::Rect r = location_; - manager_->ScrollToPoint(*this, gfx::Point(x, y)); + manager_->ScrollToPoint(*this, scroll_to); static_cast<BrowserAccessibilityManagerWin*>(manager_) ->TrackScrollingObject(this); diff --git a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc b/content/browser/browser_plugin/browser_plugin_embedder_helper.cc index aa6f680..dcae05a 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc +++ b/content/browser/browser_plugin/browser_plugin_embedder_helper.cc @@ -92,8 +92,10 @@ void BrowserPluginEmbedderHelper::OnHandleInputEvent( // Convert the window coordinates into screen coordinates. gfx::Rect guest_screen_rect(*guest_rect); - if (rvh->GetView()) - guest_screen_rect.Offset(rvh->GetView()->GetViewBounds().origin()); + if (rvh->GetView()) { + guest_screen_rect.Offset( + rvh->GetView()->GetViewBounds().OffsetFromOrigin()); + } IPC::Message* reply_message = IPC::SyncMessage::GenerateReply(&message); diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index 86c3144..4919b1f 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -387,7 +387,7 @@ void BrowserPluginGuest::ShowWidget(RenderViewHost* render_view_host, int route_id, const gfx::Rect& initial_pos) { gfx::Rect screen_pos(initial_pos); - screen_pos.Offset(guest_rect_.origin()); + screen_pos.Offset(guest_rect_.OffsetFromOrigin()); static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, screen_pos); } diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 75de051..a993a0a 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -1458,7 +1458,7 @@ void RenderViewHostImpl::OnMsgStartDragging( const WebDropData& drop_data, WebDragOperationsMask drag_operations_mask, const SkBitmap& bitmap, - const gfx::Point& bitmap_offset_in_dip) { + const gfx::Vector2d& bitmap_offset_in_dip) { RenderViewHostDelegateView* view = delegate_->GetDelegateView(); if (!view) return; diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index 7d3cf04..571512b 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -541,7 +541,7 @@ class CONTENT_EXPORT RenderViewHostImpl void OnMsgStartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask operations_allowed, const SkBitmap& bitmap, - const gfx::Point& bitmap_offset_in_dip); + const gfx::Vector2d& bitmap_offset_in_dip); void OnUpdateDragCursor(WebKit::WebDragOperation drag_operation); void OnTargetDropACK(); void OnTakeFocus(bool reverse); diff --git a/content/browser/renderer_host/render_view_host_unittest.cc b/content/browser/renderer_host/render_view_host_unittest.cc index 485a229..653c233 100644 --- a/content/browser/renderer_host/render_view_host_unittest.cc +++ b/content/browser/renderer_host/render_view_host_unittest.cc @@ -95,7 +95,7 @@ class MockDraggingRenderViewHostDelegateView virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE { + const gfx::Vector2d& image_offset) OVERRIDE { drag_url_ = drop_data.url; html_base_url_ = drop_data.html_base_url; } diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index 9d3645a..3c26fff 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -1975,7 +1975,7 @@ void RenderWidgetHostImpl::ActivateDeferredPluginHandles() { #endif } -const gfx::Point& RenderWidgetHostImpl::GetLastScrollOffset() const { +const gfx::Vector2d& RenderWidgetHostImpl::GetLastScrollOffset() const { return last_scroll_offset_; } diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h index 61b9598..3f75810 100644 --- a/content/browser/renderer_host/render_widget_host_impl.h +++ b/content/browser/renderer_host/render_widget_host_impl.h @@ -115,7 +115,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, const WebKit::WebMouseWheelEvent& wheel_event) OVERRIDE; virtual void ForwardKeyboardEvent( const NativeWebKeyboardEvent& key_event) OVERRIDE; - virtual const gfx::Point& GetLastScrollOffset() const OVERRIDE; + virtual const gfx::Vector2d& GetLastScrollOffset() const OVERRIDE; virtual RenderProcessHost* GetProcess() const OVERRIDE; virtual int GetRoutingID() const OVERRIDE; virtual RenderWidgetHostView* GetView() const OVERRIDE; @@ -819,7 +819,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, std::vector<gfx::PluginWindowHandle> deferred_plugin_handles_; // The last scroll offset of the render widget. - gfx::Point last_scroll_offset_; + gfx::Vector2d last_scroll_offset_; bool pending_mouse_lock_request_; bool allow_privileged_mouse_lock_; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 78ee6af..33bb222 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -198,7 +198,7 @@ RenderWidgetHostViewAndroid::GetNativeViewAccessible() { } void RenderWidgetHostViewAndroid::MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) { // We don't have plugin windows on Android. Do nothing. Note: this is called // from RenderWidgetHost::OnMsgUpdateRect which is itself invoked while @@ -518,7 +518,7 @@ void RenderWidgetHostViewAndroid::SetCachedPageScaleFactorLimits( } void RenderWidgetHostViewAndroid::UpdateFrameInfo( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, float page_scale_factor, const gfx::Size& content_size) { if (content_view_core_) { diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h index 54452bc..67c1f03 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.h +++ b/content/browser/renderer_host/render_widget_host_view_android.h @@ -56,7 +56,7 @@ class RenderWidgetHostViewAndroid : public RenderWidgetHostViewBase { virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; @@ -120,7 +120,7 @@ class RenderWidgetHostViewAndroid : public RenderWidgetHostViewBase { virtual void SetCachedBackgroundColor(SkColor color) OVERRIDE; virtual void SetCachedPageScaleFactorLimits(float minimum_scale, float maximum_scale) OVERRIDE; - virtual void UpdateFrameInfo(const gfx::Point& scroll_offset, + virtual void UpdateFrameInfo(const gfx::Vector2d& scroll_offset, float page_scale_factor, const gfx::Size& content_size) OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 1f873ad..eaf8125 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -446,7 +446,7 @@ gfx::NativeViewAccessible RenderWidgetHostViewAura::GetNativeViewAccessible() { } void RenderWidgetHostViewAura::MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& plugin_window_moves) { #if defined(OS_WIN) // We need to clip the rectangle to the tab's viewport, otherwise we will draw @@ -463,15 +463,15 @@ void RenderWidgetHostViewAura::MovePluginWindows( view_bounds.height()); for (size_t i = 0; i < moves.size(); ++i) { - gfx::Rect clip = moves[i].clip_rect; - clip.Offset(moves[i].window_rect.origin()); - clip.Offset(scroll_offset); + gfx::Rect clip(moves[i].clip_rect); + gfx::Vector2d view_port_offset( + moves[i].window_rect.OffsetFromOrigin() + scroll_offset); + clip.Offset(view_port_offset); clip.Intersect(view_port); - clip.Offset(-moves[i].window_rect.x(), -moves[i].window_rect.y()); - clip.Offset(-scroll_offset.x(), -scroll_offset.y()); + clip.Offset(-view_port_offset); moves[i].clip_rect = clip; - moves[i].window_rect.Offset(view_bounds.origin()); + moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin()); } MovePluginWindowsHelper(parent, moves); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index c6076f3..0c51b1e 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -75,7 +75,7 @@ class RenderWidgetHostViewAura virtual void WasShown() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.cc b/content/browser/renderer_host/render_widget_host_view_gtk.cc index 8491663..3953312 100644 --- a/content/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/content/browser/renderer_host/render_widget_host_view_gtk.cc @@ -758,7 +758,7 @@ gfx::NativeViewAccessible RenderWidgetHostViewGtk::GetNativeViewAccessible() { } void RenderWidgetHostViewGtk::MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) { for (size_t i = 0; i < moves.size(); ++i) { plugin_container_manager_.MovePluginContainer(moves[i]); @@ -1041,12 +1041,14 @@ void RenderWidgetHostViewGtk::CopyFromCompositingSurface( skia::PlatformBitmap* output) { base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); - const gfx::Rect bounds = GetViewBounds(); + gfx::Rect src_subrect_in_view = src_subrect; + src_subrect_in_view.Offset(GetViewBounds().OffsetFromOrigin()); + ui::XScopedImage image(XGetImage(ui::GetXDisplay(), ui::GetX11RootWindow(), - bounds.x() + src_subrect.x(), - bounds.y() + src_subrect.y(), - src_subrect.width(), - src_subrect.height(), + src_subrect_in_view.x(), + src_subrect_in_view.y(), + src_subrect_in_view.width(), + src_subrect_in_view.height(), AllPlanes, ZPixmap)); if (!image.get()) return; diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.h b/content/browser/renderer_host/render_widget_host_view_gtk.h index dafe8cc..f32ccdb 100644 --- a/content/browser/renderer_host/render_widget_host_view_gtk.h +++ b/content/browser/renderer_host/render_widget_host_view_gtk.h @@ -73,7 +73,7 @@ class CONTENT_EXPORT RenderWidgetHostViewGtk virtual void WasShown() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h index 61a7745..569fa86 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.h +++ b/content/browser/renderer_host/render_widget_host_view_mac.h @@ -227,7 +227,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase { virtual void WasShown() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 8962b91..fcc2088 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -486,7 +486,7 @@ gfx::NativeViewAccessible RenderWidgetHostViewMac::GetNativeViewAccessible() { } void RenderWidgetHostViewMac::MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) { TRACE_EVENT0("browser", "RenderWidgetHostViewMac::MovePluginWindows"); CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm index 80c9e02..da105df 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm @@ -115,7 +115,7 @@ class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness { geom.visible = true; geom.rects_valid = true; rwhv_mac_->MovePluginWindows( - gfx::Point(), + gfx::Vector2d(), std::vector<webkit::npapi::WebPluginGeometry>(1, geom)); return accelerated_handle; diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc index 44ab814..9feecbf 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.cc +++ b/content/browser/renderer_host/render_widget_host_view_win.cc @@ -537,7 +537,7 @@ RenderWidgetHostViewWin::GetNativeViewAccessible() { } void RenderWidgetHostViewWin::MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& plugin_window_moves) { MovePluginWindowsHelper(m_hWnd, plugin_window_moves); } @@ -713,9 +713,8 @@ void RenderWidgetHostViewWin::Redraw() { RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); // Send the invalid rect in screen coordinates. - gfx::Rect screen_rect = GetViewBounds(); gfx::Rect invalid_screen_rect(damage_bounds); - invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); + invalid_screen_rect.Offset(GetViewBounds().OffsetFromOrigin()); PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); } @@ -1327,7 +1326,7 @@ void RenderWidgetHostViewWin::DrawBackground(const RECT& dirty_rect, if (!background_.empty()) { gfx::Rect dirty_area(dirty_rect); gfx::Canvas canvas(dirty_area.size(), ui::SCALE_FACTOR_100P, true); - canvas.Translate(gfx::Point().Subtract(dirty_area.origin())); + canvas.Translate(-dirty_area.OffsetFromOrigin()); gfx::Rect dc_rect(dc->m_ps.rcPaint); // TODO(pkotwicz): Fix |background_| such that it is an ImageSkia. diff --git a/content/browser/renderer_host/render_widget_host_view_win.h b/content/browser/renderer_host/render_widget_host_view_win.h index 37560a0..7ef8d0b 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.h +++ b/content/browser/renderer_host/render_widget_host_view_win.h @@ -168,7 +168,7 @@ class RenderWidgetHostViewWin virtual void WasShown() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc index 6879b4c..c2cb5d1 100644 --- a/content/browser/renderer_host/test_render_view_host.cc +++ b/content/browser/renderer_host/test_render_view_host.cc @@ -355,7 +355,7 @@ void TestRenderViewHost::SimulateWasShown() { void TestRenderViewHost::TestOnMsgStartDragging( const WebDropData& drop_data) { WebKit::WebDragOperationsMask drag_operation = WebKit::WebDragOperationEvery; - OnMsgStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Point()); + OnMsgStartDragging(drop_data, drag_operation, SkBitmap(), gfx::Vector2d()); } void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { diff --git a/content/browser/renderer_host/test_render_view_host.h b/content/browser/renderer_host/test_render_view_host.h index baddd15..f8b72b72 100644 --- a/content/browser/renderer_host/test_render_view_host.h +++ b/content/browser/renderer_host/test_render_view_host.h @@ -88,7 +88,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostViewBase { virtual void WasShown() OVERRIDE {} virtual void WasHidden() OVERRIDE {} virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE {} virtual void Focus() OVERRIDE {} virtual void Blur() OVERRIDE {} @@ -145,7 +145,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostViewBase { virtual void SetCachedBackgroundColor(SkColor color) OVERRIDE {} virtual void SetCachedPageScaleFactorLimits(float minimum_scale, float maximum_scale) OVERRIDE {} - virtual void UpdateFrameInfo(const gfx::Point& scroll_offset, + virtual void UpdateFrameInfo(const gfx::Vector2d& scroll_offset, float page_scale_factor, const gfx::Size& content_size) OVERRIDE {} virtual void HasTouchEventHandlers(bool need_touch_events) OVERRIDE {} diff --git a/content/browser/web_contents/interstitial_page_impl.cc b/content/browser/web_contents/interstitial_page_impl.cc index 0185f5b..94b2448 100644 --- a/content/browser/web_contents/interstitial_page_impl.cc +++ b/content/browser/web_contents/interstitial_page_impl.cc @@ -82,7 +82,7 @@ class InterstitialPageImpl::InterstitialPageRVHDelegateView virtual void StartDragging(const WebDropData& drop_data, WebDragOperationsMask operations_allowed, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; @@ -709,7 +709,7 @@ void InterstitialPageImpl::InterstitialPageRVHDelegateView::StartDragging( const WebDropData& drop_data, WebDragOperationsMask allowed_operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { NOTREACHED() << "InterstitialPage does not support dragging yet."; } diff --git a/content/browser/web_contents/web_contents_drag_win.cc b/content/browser/web_contents/web_contents_drag_win.cc index 9510617..adc4cec 100644 --- a/content/browser/web_contents/web_contents_drag_win.cc +++ b/content/browser/web_contents/web_contents_drag_win.cc @@ -155,7 +155,7 @@ WebContentsDragWin::~WebContentsDragWin() { void WebContentsDragWin::StartDragging(const WebDropData& drop_data, WebDragOperationsMask ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); drag_source_ = new WebDragSource(source_window_, web_contents_); @@ -193,7 +193,7 @@ void WebContentsDragWin::StartBackgroundDragging( const GURL& page_url, const std::string& page_encoding, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { drag_drop_thread_id_ = base::PlatformThread::CurrentId(); if (DoDragging(drop_data, ops, page_url, page_encoding, @@ -308,7 +308,7 @@ bool WebContentsDragWin::DoDragging(const WebDropData& drop_data, const GURL& page_url, const std::string& page_encoding, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { ui::OSExchangeData data; if (!drop_data.download_metadata.empty()) { diff --git a/content/browser/web_contents/web_contents_drag_win.h b/content/browser/web_contents/web_contents_drag_win.h index f7b7361..12f07cc 100644 --- a/content/browser/web_contents/web_contents_drag_win.h +++ b/content/browser/web_contents/web_contents_drag_win.h @@ -48,7 +48,7 @@ class CONTENT_EXPORT WebContentsDragWin void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset); + const gfx::Vector2d& image_offset); void CancelDrag(); // DataObjectImpl::Observer implementation. @@ -75,7 +75,7 @@ class CONTENT_EXPORT WebContentsDragWin const GURL& page_url, const std::string& page_encoding, const gfx::ImageSkia& image, - const gfx::Point& image_offset); + const gfx::Vector2d& image_offset); // Called on drag-and-drop thread. void StartBackgroundDragging(const WebDropData& drop_data, @@ -83,7 +83,7 @@ class CONTENT_EXPORT WebContentsDragWin const GURL& page_url, const std::string& page_encoding, const gfx::ImageSkia& image, - const gfx::Point& image_offset); + const gfx::Vector2d& image_offset); // Called on UI thread. void EndDragging(); void CloseThread(); diff --git a/content/browser/web_contents/web_contents_view_android.cc b/content/browser/web_contents/web_contents_view_android.cc index c9f2aee..b4d67fa 100644 --- a/content/browser/web_contents/web_contents_view_android.cc +++ b/content/browser/web_contents/web_contents_view_android.cc @@ -183,7 +183,7 @@ void WebContentsViewAndroid::StartDragging( const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { NOTIMPLEMENTED(); } diff --git a/content/browser/web_contents/web_contents_view_android.h b/content/browser/web_contents/web_contents_view_android.h index 40be029..ce7537e 100644 --- a/content/browser/web_contents/web_contents_view_android.h +++ b/content/browser/web_contents/web_contents_view_android.h @@ -64,7 +64,7 @@ class WebContentsViewAndroid : public WebContentsView, virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc index c50f016..6a03aad 100644 --- a/content/browser/web_contents/web_contents_view_aura.cc +++ b/content/browser/web_contents/web_contents_view_aura.cc @@ -437,7 +437,7 @@ void WebContentsViewAura::StartDragging( const WebDropData& drop_data, WebKit::WebDragOperationsMask operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); if (!aura::client::GetDragDropClient(root_window)) return; diff --git a/content/browser/web_contents/web_contents_view_aura.h b/content/browser/web_contents/web_contents_view_aura.h index ef37095..cd77127 100644 --- a/content/browser/web_contents/web_contents_view_aura.h +++ b/content/browser/web_contents/web_contents_view_aura.h @@ -80,7 +80,7 @@ class CONTENT_EXPORT WebContentsViewAura virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_view_gtk.cc b/content/browser/web_contents/web_contents_view_gtk.cc index a2f3524..f3a35dd 100644 --- a/content/browser/web_contents/web_contents_view_gtk.cc +++ b/content/browser/web_contents/web_contents_view_gtk.cc @@ -342,7 +342,7 @@ void WebContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, void WebContentsViewGtk::StartDragging(const WebDropData& drop_data, WebDragOperationsMask ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { DCHECK(GetContentNativeView()); RenderWidgetHostViewGtk* view_gtk = static_cast<RenderWidgetHostViewGtk*>( diff --git a/content/browser/web_contents/web_contents_view_gtk.h b/content/browser/web_contents/web_contents_view_gtk.h index 5ece503..0286e81 100644 --- a/content/browser/web_contents/web_contents_view_gtk.h +++ b/content/browser/web_contents/web_contents_view_gtk.h @@ -79,7 +79,7 @@ class CONTENT_EXPORT WebContentsViewGtk virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_view_mac.h b/content/browser/web_contents/web_contents_view_mac.h index 08197d2..af0c4d4 100644 --- a/content/browser/web_contents/web_contents_view_mac.h +++ b/content/browser/web_contents/web_contents_view_mac.h @@ -29,7 +29,7 @@ class WebContentsViewMac; } namespace gfx { -class Point; +class Vector2d; } @interface WebContentsViewCocoa : BaseView { @@ -97,7 +97,7 @@ class WebContentsViewMac : public WebContentsView, virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm index b619774..342a051 100644 --- a/content/browser/web_contents/web_contents_view_mac.mm +++ b/content/browser/web_contents/web_contents_view_mac.mm @@ -174,7 +174,7 @@ void WebContentsViewMac::StartDragging( const WebDropData& drop_data, WebDragOperationsMask allowed_operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { // By allowing nested tasks, the code below also allows Close(), // which would deallocate |this|. The same problem can occur while // processing -sendEvent:, so Close() is deferred in that case. @@ -186,7 +186,8 @@ void WebContentsViewMac::StartDragging( // processing events. MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); - NSPoint offset = NSPointFromCGPoint(image_offset.ToCGPoint()); + NSPoint offset = NSPointFromCGPoint( + gfx::PointAtOffsetFromOrigin(image_offset).ToCGPoint()); [cocoa_view_ startDragWithDropData:drop_data dragOperationMask:mask image:gfx::NSImageFromImageSkia(image) diff --git a/content/browser/web_contents/web_contents_view_win.cc b/content/browser/web_contents/web_contents_view_win.cc index d604176..64844f1 100644 --- a/content/browser/web_contents/web_contents_view_win.cc +++ b/content/browser/web_contents/web_contents_view_win.cc @@ -263,7 +263,7 @@ void WebContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds, void WebContentsViewWin::StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { drag_handler_ = new WebContentsDragWin( GetNativeView(), web_contents_, diff --git a/content/browser/web_contents/web_contents_view_win.h b/content/browser/web_contents/web_contents_view_win.h index ebb2c81..9d4d010 100644 --- a/content/browser/web_contents/web_contents_view_win.h +++ b/content/browser/web_contents/web_contents_view_win.h @@ -88,7 +88,7 @@ class CONTENT_EXPORT WebContentsViewWin virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask operations, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/content/browser/web_contents/web_drag_source_gtk.cc b/content/browser/web_contents/web_drag_source_gtk.cc index 1090728..b1dda32 100644 --- a/content/browser/web_contents/web_drag_source_gtk.cc +++ b/content/browser/web_contents/web_drag_source_gtk.cc @@ -73,7 +73,7 @@ void WebDragSourceGtk::StartDragging(const WebDropData& drop_data, WebDragOperationsMask allowed_ops, GdkEventButton* last_mouse_down, const SkBitmap& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { // Guard against re-starting before previous drag completed. if (drag_context_) { NOTREACHED(); diff --git a/content/browser/web_contents/web_drag_source_gtk.h b/content/browser/web_contents/web_drag_source_gtk.h index fe2038d..979047a 100644 --- a/content/browser/web_contents/web_drag_source_gtk.h +++ b/content/browser/web_contents/web_drag_source_gtk.h @@ -17,7 +17,7 @@ #include "ui/base/gtk/gtk_signal.h" #include "ui/base/gtk/gtk_signal_registrar.h" #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/point.h" +#include "ui/gfx/vector2d.h" class SkBitmap; struct WebDropData; @@ -39,7 +39,7 @@ class CONTENT_EXPORT WebDragSourceGtk : public MessageLoopForUI::Observer { WebKit::WebDragOperationsMask allowed_ops, GdkEventButton* last_mouse_down, const SkBitmap& image, - const gfx::Point& image_offset); + const gfx::Vector2d& image_offset); // MessageLoop::Observer implementation: virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; @@ -70,7 +70,7 @@ class CONTENT_EXPORT WebDragSourceGtk : public MessageLoopForUI::Observer { // The image used for depicting the drag, and the offset between the cursor // and the top left pixel. GdkPixbuf* drag_pixbuf_; - gfx::Point image_offset_; + gfx::Vector2d image_offset_; // The mime type for the file contents of the current drag (if any). GdkAtom drag_file_mime_type_; diff --git a/content/common/browser_plugin_messages.h b/content/common/browser_plugin_messages.h index ea4d847..dfed79b 100644 --- a/content/common/browser_plugin_messages.h +++ b/content/common/browser_plugin_messages.h @@ -228,7 +228,7 @@ IPC_STRUCT_BEGIN(BrowserPluginMsg_UpdateRect_Params) IPC_STRUCT_MEMBER(gfx::Rect, scroll_rect) // The scroll offset of the render view. - IPC_STRUCT_MEMBER(gfx::Point, scroll_offset) + IPC_STRUCT_MEMBER(gfx::Vector2d, scroll_offset) // The regions of the bitmap (in view coords) that contain updated pixels. // In the case of scrolling, this includes the scroll damage rect. diff --git a/content/common/drag_messages.h b/content/common/drag_messages.h index f1d8ce7..0ad3db8 100644 --- a/content/common/drag_messages.h +++ b/content/common/drag_messages.h @@ -10,6 +10,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" #include "ui/gfx/point.h" +#include "ui/gfx/vector2d.h" #include "webkit/glue/webdropdata.h" #define IPC_MESSAGE_START DragMsgStart @@ -57,7 +58,7 @@ IPC_MESSAGE_ROUTED4(DragHostMsg_StartDragging, WebDropData /* drop_data */, WebKit::WebDragOperationsMask /* ops_allowed */, SkBitmap /* image */, - gfx::Point /* image_offset */) + gfx::Vector2d /* image_offset */) // The page wants to update the mouse cursor during a drag & drop operation. // |is_drop_target| is true if the mouse is over a valid drop target. diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 81da788..41297b3 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -44,6 +44,7 @@ #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_f.h" +#include "ui/gfx/vector2d.h" #include "webkit/glue/webcookie.h" #include "webkit/glue/webmenuitem.h" #include "webkit/glue/webpreferences.h" @@ -560,7 +561,7 @@ IPC_STRUCT_BEGIN(ViewHostMsg_UpdateRect_Params) IPC_STRUCT_MEMBER(gfx::Rect, scroll_rect) // The scroll offset of the render view. - IPC_STRUCT_MEMBER(gfx::Point, scroll_offset) + IPC_STRUCT_MEMBER(gfx::Vector2d, scroll_offset) // The regions of the bitmap (in view coords) that contain updated pixels. // In the case of scrolling, this includes the scroll damage rect. diff --git a/content/plugin/webplugin_proxy.cc b/content/plugin/webplugin_proxy.cc index c74af5b..0d5ed27 100644 --- a/content/plugin/webplugin_proxy.cc +++ b/content/plugin/webplugin_proxy.cc @@ -349,7 +349,7 @@ void WebPluginProxy::Paint(const gfx::Rect& rect) { // Clear the damaged area so that if the plugin doesn't paint there we won't // end up with the old values. gfx::Rect offset_rect = rect; - offset_rect.Offset(delegate_->GetRect().origin()); + offset_rect.Offset(delegate_->GetRect().OffsetFromOrigin()); #if defined(OS_MACOSX) CGContextSaveGState(windowless_context()); // It is possible for windowless_contexts_ to change during plugin painting diff --git a/content/port/browser/render_view_host_delegate_view.h b/content/port/browser/render_view_host_delegate_view.h index b59d6e0..4b84cb84 100644 --- a/content/port/browser/render_view_host_delegate_view.h +++ b/content/port/browser/render_view_host_delegate_view.h @@ -18,8 +18,8 @@ struct WebMenuItem; namespace gfx { class ImageSkia; -class Point; class Rect; +class Vector2d; } namespace content { @@ -53,7 +53,7 @@ class CONTENT_EXPORT RenderViewHostDelegateView { virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) {} + const gfx::Vector2d& image_offset) {} // The page wants to update the mouse cursor during a drag & drop operation. // |operation| describes the current operation (none, move, copy, link.) diff --git a/content/port/browser/render_widget_host_view_port.h b/content/port/browser/render_widget_host_view_port.h index ef4f507..ffa1b6d 100644 --- a/content/port/browser/render_widget_host_view_port.h +++ b/content/port/browser/render_widget_host_view_port.h @@ -79,7 +79,7 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { // Moves all plugin windows as described in the given list. // |scroll_offset| is the scroll offset of the render view. virtual void MovePluginWindows( - const gfx::Point& scroll_offset, + const gfx::Vector2d& scroll_offset, const std::vector<webkit::npapi::WebPluginGeometry>& moves) = 0; // Take focus from the associated View component. @@ -229,7 +229,7 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { #if defined(OS_ANDROID) virtual void SetCachedPageScaleFactorLimits(float minimum_scale, float maximum_scale) = 0; - virtual void UpdateFrameInfo(const gfx::Point& scroll_offset, + virtual void UpdateFrameInfo(const gfx::Vector2d& scroll_offset, float page_scale_factor, const gfx::Size& content_size) = 0; virtual void HasTouchEventHandlers(bool need_touch_events) = 0; diff --git a/content/public/browser/render_widget_host.h b/content/public/browser/render_widget_host.h index 6db9eaf..ae0b63d 100644 --- a/content/public/browser/render_widget_host.h +++ b/content/public/browser/render_widget_host.h @@ -201,7 +201,7 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Sender { virtual void ForwardKeyboardEvent( const NativeWebKeyboardEvent& key_event) = 0; - virtual const gfx::Point& GetLastScrollOffset() const = 0; + virtual const gfx::Vector2d& GetLastScrollOffset() const = 0; virtual RenderProcessHost* GetProcess() const = 0; diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc index 9565865..7a0200a 100644 --- a/content/public/common/common_param_traits.cc +++ b/content/public/common/common_param_traits.cc @@ -151,6 +151,27 @@ void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); } +void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& v) { + m->WriteInt(v.x()); + m->WriteInt(v.y()); +} + +bool ParamTraits<gfx::Vector2d>::Read(const Message* m, + PickleIterator* iter, + gfx::Vector2d* r) { + int x, y; + if (!m->ReadInt(iter, &x) || + !m->ReadInt(iter, &y)) + return false; + r->set_x(x); + r->set_y(y); + return true; +} + +void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { + l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); +} + void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { m->WriteInt(p.x()); m->WriteInt(p.y()); diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h index 8128a9e..ce5a668 100644 --- a/content/public/common/common_param_traits.h +++ b/content/public/common/common_param_traits.h @@ -33,6 +33,7 @@ class Point; class Rect; class RectF; class Size; +class Vector2d; } // namespace gfx namespace net { @@ -82,6 +83,14 @@ struct CONTENT_EXPORT ParamTraits<gfx::Size> { }; template <> +struct CONTENT_EXPORT ParamTraits<gfx::Vector2d> { + typedef gfx::Vector2d param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> struct CONTENT_EXPORT ParamTraits<gfx::Rect> { typedef gfx::Rect param_type; static void Write(Message* m, const param_type& p); diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 26540ed..cbd27af 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2162,12 +2162,10 @@ void RenderViewImpl::showContextMenu( gfx::Rect start_rect; gfx::Rect end_rect; GetSelectionBounds(&start_rect, &end_rect); - gfx::Point start_point(start_rect.x(), - start_rect.bottom()); - gfx::Point end_point(end_rect.right(), - end_rect.bottom()); - params.selection_start = GetScrollOffset().Add(start_point); - params.selection_end = GetScrollOffset().Add(end_point); + params.selection_start = + gfx::Point(start_rect.x(), start_rect.bottom()) + GetScrollOffset(); + params.selection_end = + gfx::Point(end_rect.right(), end_rect.bottom()) + GetScrollOffset(); #endif Send(new ViewHostMsg_ContextMenu(routing_id_, params)); @@ -2237,9 +2235,10 @@ void RenderViewImpl::startDragging(WebFrame* frame, const WebDragData& data, WebDragOperationsMask mask, const WebImage& image, - const WebPoint& imageOffset) { + const WebPoint& webImageOffset) { WebDropData drop_data(data); drop_data.referrer_policy = frame->document().referrerPolicy(); + gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y); Send(new DragHostMsg_StartDragging(routing_id_, drop_data, mask, @@ -5518,9 +5517,9 @@ webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint( paint_bounds, dib, location, clip, scale_factor); } -gfx::Point RenderViewImpl::GetScrollOffset() { +gfx::Vector2d RenderViewImpl::GetScrollOffset() { WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); - return gfx::Point(scroll_offset.width, scroll_offset.height); + return gfx::Vector2d(scroll_offset.width, scroll_offset.height); } void RenderViewImpl::OnClearFocusedNode() { diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 16f1bf8..4bf249c 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -738,7 +738,7 @@ class RenderViewImpl : public RenderWidget, gfx::Rect* location, gfx::Rect* clip, float* scale_factor) OVERRIDE; - virtual gfx::Point GetScrollOffset() OVERRIDE; + virtual gfx::Vector2d GetScrollOffset() OVERRIDE; virtual void DidHandleKeyEvent() OVERRIDE; virtual bool WillHandleMouseEvent( const WebKit::WebMouseEvent& event) OVERRIDE; diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index 78e49a7..9e723b5 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -1626,9 +1626,9 @@ webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( return NULL; } -gfx::Point RenderWidget::GetScrollOffset() { +gfx::Vector2d RenderWidget::GetScrollOffset() { // Bare RenderWidgets don't support scroll offset. - return gfx::Point(0, 0); + return gfx::Vector2d(); } void RenderWidget::SetHidden(bool hidden) { diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h index f818a89..eff42ccb 100644 --- a/content/renderer/render_widget.h +++ b/content/renderer/render_widget.h @@ -330,7 +330,7 @@ class CONTENT_EXPORT RenderWidget // Gets the scroll offset of this widget, if this widget has a notion of // scroll offset. - virtual gfx::Point GetScrollOffset(); + virtual gfx::Vector2d GetScrollOffset(); // Sets the "hidden" state of this widget. All accesses to is_hidden_ should // use this method so that we can properly inform the RenderThread of our diff --git a/content/test/test_web_contents_view.cc b/content/test/test_web_contents_view.cc index fd69240..ce8b6c7 100644 --- a/content/test/test_web_contents_view.cc +++ b/content/test/test_web_contents_view.cc @@ -29,7 +29,7 @@ void TestWebContentsView::StartDragging( const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) { + const gfx::Vector2d& image_offset) { } void TestWebContentsView::UpdateDragCursor(WebKit::WebDragOperation operation) { diff --git a/content/test/test_web_contents_view.h b/content/test/test_web_contents_view.h index 371359a..092cf18 100644 --- a/content/test/test_web_contents_view.h +++ b/content/test/test_web_contents_view.h @@ -30,7 +30,7 @@ class TestWebContentsView : public WebContentsView, virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, - const gfx::Point& image_offset) OVERRIDE; + const gfx::Vector2d& image_offset) OVERRIDE; virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; diff --git a/ui/app_list/apps_grid_view.cc b/ui/app_list/apps_grid_view.cc index f9e21c9..08ab470 100644 --- a/ui/app_list/apps_grid_view.cc +++ b/ui/app_list/apps_grid_view.cc @@ -169,15 +169,14 @@ void AppsGridView::InitiateDrag(views::View* view, return; drag_view_ = view; - drag_offset_ = event.location(); + drag_start_ = event.location(); } void AppsGridView::UpdateDrag(views::View* view, Pointer pointer, const ui::LocatedEvent& event) { if (!dragging() && drag_view_ && - ExceededDragThreshold(event.x() - drag_offset_.x(), - event.y() - drag_offset_.y())) { + ExceededDragThreshold(event.location() - drag_start_)) { drag_pointer_ = pointer; // Move the view to the front so that it appears on top of other views. ReorderChildView(drag_view_, -1); @@ -198,7 +197,8 @@ void AppsGridView::UpdateDrag(views::View* view, if (last_drop_target != drop_target_) AnimateToIdealBounds(); - drag_view_->SetPosition(last_drag_point_.Subtract(drag_offset_)); + drag_view_->SetPosition( + gfx::PointAtOffsetFromOrigin(last_drag_point_ - drag_start_)); } } diff --git a/ui/app_list/apps_grid_view.h b/ui/app_list/apps_grid_view.h index 13d1bcb..873c4d2 100644 --- a/ui/app_list/apps_grid_view.h +++ b/ui/app_list/apps_grid_view.h @@ -183,7 +183,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View, views::View* selected_view_; views::View* drag_view_; - gfx::Point drag_offset_; + gfx::Point drag_start_; Pointer drag_pointer_; Index drop_target_; diff --git a/ui/aura/client/window_move_client.h b/ui/aura/client/window_move_client.h index 2d2a8cb..0315841 100644 --- a/ui/aura/client/window_move_client.h +++ b/ui/aura/client/window_move_client.h @@ -6,6 +6,7 @@ #define UI_AURA_CLIENT_WINDOW_MOVE_CLIENT_H_ #include "ui/aura/aura_export.h" +#include "ui/gfx/vector2d.h" namespace gfx { class Point; @@ -29,7 +30,7 @@ class AURA_EXPORT WindowMoveClient { // Returns MOVE_SUCCESSFUL if the move has completed successfully, or // MOVE_CANCELED otherwise. virtual WindowMoveResult RunMoveLoop(Window* window, - const gfx::Point& drag_offset) = 0; + const gfx::Vector2d& drag_offset) = 0; // Ends a previously started move loop. virtual void EndMoveLoop() = 0; diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc index a2eb897..2a6daea 100644 --- a/ui/aura/test/event_generator.cc +++ b/ui/aura/test/event_generator.cc @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "ui/aura/root_window.h" #include "ui/base/events/event.h" +#include "ui/gfx/vector2d_conversions.h" #if defined(USE_X11) #include <X11/Xlib.h> @@ -126,10 +127,11 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) { DCHECK_GT(count, 0); const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; - const gfx::Point diff = point.Subtract(current_location_); - for (int i = 1; i <= count; i++) { - const gfx::Point move_point = current_location_.Add( - gfx::Point(diff.x() / count * i, diff.y() / count * i)); + gfx::Vector2dF diff(point - current_location_); + for (float i = 1; i <= count; i++) { + gfx::Vector2dF step(diff); + step.Scale(i / count); + gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); Dispatch(mouseev); } diff --git a/ui/aura/test/event_generator.h b/ui/aura/test/event_generator.h index 01e5a9d..29aebcf 100644 --- a/ui/aura/test/event_generator.h +++ b/ui/aura/test/event_generator.h @@ -85,7 +85,7 @@ class EventGenerator { } void MoveMouseBy(int x, int y) { - MoveMouseTo(current_location_.Add(gfx::Point(x, y))); + MoveMouseTo(current_location_.Add(gfx::Vector2d(x, y))); } // Generates events to drag mouse to given |point|. @@ -96,7 +96,7 @@ class EventGenerator { } void DragMouseBy(int dx, int dy) { - DragMouseTo(current_location_.Add(gfx::Point(dx, dy))); + DragMouseTo(current_location_.Add(gfx::Vector2d(dx, dy))); } // Generates events to move the mouse to the center of the window. @@ -120,7 +120,7 @@ class EventGenerator { } void PressMoveAndReleaseTouchBy(int x, int y) { - PressMoveAndReleaseTouchTo(current_location_.Add(gfx::Point(x, y))); + PressMoveAndReleaseTouchTo(current_location_.Add(gfx::Vector2d(x, y))); } // Generates press, move and release events to move touch diff --git a/ui/base/dragdrop/drag_utils.cc b/ui/base/dragdrop/drag_utils.cc index 97e855c..9c58491 100644 --- a/ui/base/dragdrop/drag_utils.cc +++ b/ui/base/dragdrop/drag_utils.cc @@ -93,14 +93,13 @@ void CreateDragImageForFile(const FilePath& file_name, // ImageSkia takes ownership of |source|. gfx::ImageSkia image = gfx::ImageSkia(source, size); - SetDragImageOnDataObject(image, size, - gfx::Point(size.width() / 2, kLinkDragImageVPadding), - data_object); + gfx::Vector2d cursor_offset(size.width() / 2, kLinkDragImageVPadding); + SetDragImageOnDataObject(image, size, cursor_offset, data_object); } void SetDragImageOnDataObject(const gfx::Canvas& canvas, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object) { gfx::ImageSkia image = gfx::ImageSkia(canvas.ExtractImageRep()); SetDragImageOnDataObject(image, size, cursor_offset, data_object); diff --git a/ui/base/dragdrop/drag_utils.h b/ui/base/dragdrop/drag_utils.h index c2bf02c..1f84d90 100644 --- a/ui/base/dragdrop/drag_utils.h +++ b/ui/base/dragdrop/drag_utils.h @@ -15,8 +15,8 @@ class GURL; namespace gfx { class Canvas; class ImageSkia; -class Point; class Size; +class Vector2d; } namespace ui { @@ -39,7 +39,7 @@ UI_EXPORT void CreateDragImageForFile(const FilePath& file_name, // the hotspot for the drag image. UI_EXPORT void SetDragImageOnDataObject(const gfx::Canvas& canvas, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object); // Sets the drag image on data_object from the supplied ImageSkia. width/height @@ -47,7 +47,7 @@ UI_EXPORT void SetDragImageOnDataObject(const gfx::Canvas& canvas, // the hotspot for the drag image. UI_EXPORT void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object); } // namespace drag_utils diff --git a/ui/base/dragdrop/drag_utils_aura.cc b/ui/base/dragdrop/drag_utils_aura.cc index 63a22aa..07fd467 100644 --- a/ui/base/dragdrop/drag_utils_aura.cc +++ b/ui/base/dragdrop/drag_utils_aura.cc @@ -9,14 +9,14 @@ #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image_skia.h" -#include "ui/gfx/point.h" #include "ui/gfx/size.h" +#include "ui/gfx/vector2d.h" namespace drag_utils { void SetDragImageOnDataObject(const gfx::ImageSkia& image, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object) { ui::OSExchangeDataProviderAura& provider( static_cast<ui::OSExchangeDataProviderAura&>(data_object->provider())); diff --git a/ui/base/dragdrop/drag_utils_gtk.cc b/ui/base/dragdrop/drag_utils_gtk.cc index e97ba9e..7a3517b 100644 --- a/ui/base/dragdrop/drag_utils_gtk.cc +++ b/ui/base/dragdrop/drag_utils_gtk.cc @@ -19,7 +19,7 @@ namespace drag_utils { void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object) { ui::OSExchangeDataProviderGtk& provider( static_cast<ui::OSExchangeDataProviderGtk&>(data_object->provider())); diff --git a/ui/base/dragdrop/drag_utils_win.cc b/ui/base/dragdrop/drag_utils_win.cc index f7d05ee..9a3ab56 100644 --- a/ui/base/dragdrop/drag_utils_win.cc +++ b/ui/base/dragdrop/drag_utils_win.cc @@ -21,7 +21,7 @@ namespace drag_utils { static void SetDragImageOnDataObject(HBITMAP hbitmap, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, IDataObject* data_object) { base::win::ScopedComPtr<IDragSourceHelper> helper; HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, @@ -31,7 +31,7 @@ static void SetDragImageOnDataObject(HBITMAP hbitmap, sdi.sizeDragImage = size.ToSIZE(); sdi.crColorKey = 0xFFFFFFFF; sdi.hbmpDragImage = hbitmap; - sdi.ptOffset = cursor_offset.ToPOINT(); + sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT(); helper->InitializeFromBitmap(&sdi, data_object); } } @@ -56,7 +56,7 @@ static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) { void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia, const gfx::Size& size, - const gfx::Point& cursor_offset, + const gfx::Vector2d& cursor_offset, ui::OSExchangeData* data_object) { DCHECK(data_object && !size.IsEmpty()); // InitializeFromBitmap() doesn't expect an alpha channel and is confused diff --git a/ui/base/dragdrop/os_exchange_data_provider_aura.h b/ui/base/dragdrop/os_exchange_data_provider_aura.h index 505e2c1..14c684c 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_aura.h +++ b/ui/base/dragdrop/os_exchange_data_provider_aura.h @@ -12,7 +12,7 @@ #include "googleurl/src/gurl.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/image/image_skia.h" -#include "ui/gfx/point.h" +#include "ui/gfx/vector2d.h" namespace ui { @@ -63,10 +63,10 @@ class UI_EXPORT OSExchangeDataProviderAura : public OSExchangeData::Provider { } const gfx::ImageSkia& drag_image() const { return drag_image_; } - void set_drag_image_offset(const gfx::Point& drag_image_offset) { + void set_drag_image_offset(const gfx::Vector2d& drag_image_offset) { drag_image_offset_ = drag_image_offset; } - const gfx::Point& drag_image_offset() const { return drag_image_offset_; } + const gfx::Vector2d& drag_image_offset() const { return drag_image_offset_; } private: typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; @@ -94,7 +94,7 @@ class UI_EXPORT OSExchangeDataProviderAura : public OSExchangeData::Provider { // Drag image and offset data. gfx::ImageSkia drag_image_; - gfx::Point drag_image_offset_; + gfx::Vector2d drag_image_offset_; // For HTML format string16 html_; diff --git a/ui/base/dragdrop/os_exchange_data_provider_gtk.cc b/ui/base/dragdrop/os_exchange_data_provider_gtk.cc index 648bff7..8211563 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_gtk.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_gtk.cc @@ -221,8 +221,9 @@ bool OSExchangeDataProviderGtk::GetPlainTextURL(GURL* url) const { return true; } -void OSExchangeDataProviderGtk::SetDragImage(GdkPixbuf* drag_image, - const gfx::Point& cursor_offset) { +void OSExchangeDataProviderGtk::SetDragImage( + GdkPixbuf* drag_image, + const gfx::Vector2d& cursor_offset) { if (drag_image_) g_object_unref(drag_image_); g_object_ref(drag_image); diff --git a/ui/base/dragdrop/os_exchange_data_provider_gtk.h b/ui/base/dragdrop/os_exchange_data_provider_gtk.h index 98cb739..8a72edd 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_gtk.h +++ b/ui/base/dragdrop/os_exchange_data_provider_gtk.h @@ -16,7 +16,7 @@ #include "base/string16.h" #include "googleurl/src/gurl.h" #include "ui/base/dragdrop/os_exchange_data.h" -#include "ui/gfx/point.h" +#include "ui/gfx/vector2d.h" namespace ui { @@ -85,9 +85,9 @@ class UI_EXPORT OSExchangeDataProviderGtk : public OSExchangeData::Provider { // Set the image and cursor offset data for this drag. Will // increment the ref count of pixbuf. - void SetDragImage(GdkPixbuf* pixbuf, const gfx::Point& cursor_offset); + void SetDragImage(GdkPixbuf* pixbuf, const gfx::Vector2d& cursor_offset); GdkPixbuf* drag_image() const { return drag_image_; } - gfx::Point cursor_offset() const { return cursor_offset_; } + gfx::Vector2d cursor_offset() const { return cursor_offset_; } private: typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; @@ -121,7 +121,7 @@ class UI_EXPORT OSExchangeDataProviderGtk : public OSExchangeData::Provider { // Drag image and offset data. GdkPixbuf* drag_image_; - gfx::Point cursor_offset_; + gfx::Vector2d cursor_offset_; DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderGtk); }; diff --git a/ui/base/gestures/gesture_recognizer_impl.cc b/ui/base/gestures/gesture_recognizer_impl.cc index 78adfab..a18f6ce 100644 --- a/ui/base/gestures/gesture_recognizer_impl.cc +++ b/ui/base/gestures/gesture_recognizer_impl.cc @@ -125,19 +125,20 @@ GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( GestureConsumer* GestureRecognizerImpl::GetTargetForLocation( const gfx::Point& location) { const GesturePoint* closest_point = NULL; - int closest_distance_squared = 0; + int64 closest_distance_squared = 0; std::map<GestureConsumer*, GestureSequence*>::iterator i; for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) { const GesturePoint* points = i->second->points(); for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) { if (!points[j].in_use()) continue; - gfx::Point delta = - points[j].last_touch_position().Subtract(location); - int distance = delta.x() * delta.x() + delta.y() * delta.y(); - if (!closest_point || distance < closest_distance_squared) { + gfx::Vector2d delta = points[j].last_touch_position() - location; + // Relative distance is all we need here, so LengthSquared() is + // appropriate, and cheaper than Length(). + int64 distance_squared = delta.LengthSquared(); + if (!closest_point || distance_squared < closest_distance_squared) { closest_point = &points[j]; - closest_distance_squared = distance; + closest_distance_squared = distance_squared; } } } diff --git a/ui/base/gtk/gtk_screen_util.cc b/ui/base/gtk/gtk_screen_util.cc index f0ef4d3..000f950 100644 --- a/ui/base/gtk/gtk_screen_util.cc +++ b/ui/base/gtk/gtk_screen_util.cc @@ -26,12 +26,12 @@ gfx::Point ClientPoint(GtkWidget* widget) { return gfx::Point(x, y); } -gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { +gfx::Vector2d GetWidgetScreenOffset(GtkWidget* widget) { GdkWindow* window = gtk_widget_get_window(widget); if (!window) { NOTREACHED() << "Must only be called on realized widgets."; - return gfx::Point(0, 0); + return gfx::Vector2d(0, 0); } gint x, y; @@ -44,17 +44,15 @@ gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { y += allocation.y; } - return gfx::Point(x, y); + return gfx::Vector2d(x, y); } gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { - gfx::Point position = GetWidgetScreenPosition(widget); - GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); - return gfx::Rect(position.x(), position.y(), - allocation.width, allocation.height); + return gfx::Rect(PointAtOffsetFromOrigin(GetWidgetScreenOffset(widget)), + gfx::Size(allocation.width, allocation.height)); } } // namespace ui diff --git a/ui/base/gtk/gtk_screen_util.h b/ui/base/gtk/gtk_screen_util.h index 3120750..b916cf2 100644 --- a/ui/base/gtk/gtk_screen_util.h +++ b/ui/base/gtk/gtk_screen_util.h @@ -10,6 +10,7 @@ #include "ui/base/ui_export.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" +#include "ui/gfx/vector2d.h" namespace ui { @@ -22,8 +23,8 @@ UI_EXPORT gfx::Point ScreenPoint(GtkWidget* widget); // Get the current location of the mouse cursor relative to the widget. UI_EXPORT gfx::Point ClientPoint(GtkWidget* widget); -// Gets the position of a gtk widget in screen coordinates. -UI_EXPORT gfx::Point GetWidgetScreenPosition(GtkWidget* widget); +// Gets the offset of a gtk widget from the origin in screen coordinates. +UI_EXPORT gfx::Vector2d GetWidgetScreenOffset(GtkWidget* widget); // Returns the bounds of the specified widget in screen coordinates. UI_EXPORT gfx::Rect GetWidgetScreenBounds(GtkWidget* widget); diff --git a/ui/gfx/blit.cc b/ui/gfx/blit.cc index 41da3f5..c6c8d672 100644 --- a/ui/gfx/blit.cc +++ b/ui/gfx/blit.cc @@ -9,6 +9,7 @@ #include "skia/ext/platform_canvas.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" +#include "ui/gfx/vector2d.h" #if defined(OS_OPENBSD) #include <cairo.h> @@ -128,7 +129,7 @@ void BlitCanvasToCanvas(SkCanvas *dst_canvas, void ScrollCanvas(SkCanvas* canvas, const gfx::Rect& in_clip, - const gfx::Point& amount) { + const gfx::Vector2d& amount) { DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. #if defined(OS_WIN) // If we have a PlatformCanvas, we should use ScrollDC. Otherwise, fall diff --git a/ui/gfx/blit.h b/ui/gfx/blit.h index d2ed2cf..01fa4f3 100644 --- a/ui/gfx/blit.h +++ b/ui/gfx/blit.h @@ -14,6 +14,7 @@ namespace gfx { class Point; class Rect; +class Vector2d; // Blits a rectangle from the source context into the destination context. UI_EXPORT void BlitContextToContext(NativeDrawingContext dst_context, @@ -44,7 +45,7 @@ UI_EXPORT void BlitCanvasToCanvas(SkCanvas *dst_canvas, // may implement those operations differently. UI_EXPORT void ScrollCanvas(SkCanvas* canvas, const Rect& clip, - const Point& amount); + const Vector2d& amount); } // namespace gfx diff --git a/ui/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc index 72e1c26..a0c4de9 100644 --- a/ui/gfx/blit_unittest.cc +++ b/ui/gfx/blit_unittest.cc @@ -76,12 +76,12 @@ TEST(Blit, ScrollCanvas) { // Scroll none and make sure it's a NOP. gfx::ScrollCanvas(&canvas, gfx::Rect(0, 0, kCanvasWidth, kCanvasHeight), - gfx::Point(0, 0)); + gfx::Vector2d(0, 0)); VerifyCanvasValues<5, 5>(&canvas, initial_values); // Scroll the center 3 pixels up one. gfx::Rect center_three(1, 1, 3, 3); - gfx::ScrollCanvas(&canvas, center_three, gfx::Point(0, -1)); + gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, -1)); uint8 scroll_up_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x21, 0x22, 0x23, 0x14 }, @@ -92,7 +92,7 @@ TEST(Blit, ScrollCanvas) { // Reset and scroll the center 3 pixels down one. SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Point(0, 1)); + gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, 1)); uint8 scroll_down_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x12, 0x13, 0x14 }, @@ -103,7 +103,7 @@ TEST(Blit, ScrollCanvas) { // Reset and scroll the center 3 pixels right one. SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Point(1, 0)); + gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(1, 0)); uint8 scroll_right_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x11, 0x12, 0x14 }, @@ -114,7 +114,7 @@ TEST(Blit, ScrollCanvas) { // Reset and scroll the center 3 pixels left one. SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Point(-1, 0)); + gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(-1, 0)); uint8 scroll_left_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x12, 0x13, 0x13, 0x14 }, @@ -125,7 +125,7 @@ TEST(Blit, ScrollCanvas) { // Diagonal scroll. SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Point(2, 2)); + gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(2, 2)); uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x12, 0x13, 0x14 }, diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc index 936af4b..bf41bc1 100644 --- a/ui/gfx/canvas.cc +++ b/ui/gfx/canvas.cc @@ -190,8 +190,8 @@ bool Canvas::GetClipBounds(gfx::Rect* bounds) { return has_non_empty_clip; } -void Canvas::Translate(const gfx::Point& point) { - canvas_->translate(SkIntToScalar(point.x()), SkIntToScalar(point.y())); +void Canvas::Translate(const gfx::Vector2d& offset) { + canvas_->translate(SkIntToScalar(offset.x()), SkIntToScalar(offset.y())); } void Canvas::Scale(int x_scale, int y_scale) { diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h index 4660407..0e080fa 100644 --- a/ui/gfx/canvas.h +++ b/ui/gfx/canvas.h @@ -196,7 +196,7 @@ class UI_EXPORT Canvas { // |bounds| parameter, and returns true if it is non empty. bool GetClipBounds(gfx::Rect* bounds); - void Translate(const gfx::Point& point); + void Translate(const gfx::Vector2d& offset); void Scale(int x_scale, int y_scale); diff --git a/ui/gfx/point.cc b/ui/gfx/point.cc index 322413e..e0b5595 100644 --- a/ui/gfx/point.cc +++ b/ui/gfx/point.cc @@ -12,22 +12,23 @@ namespace gfx { -template class PointBase<Point, int>; +template class PointBase<Point, int, Vector2d>; -Point::Point() : PointBase<Point, int>(0, 0) { +Point::Point() : PointBase<Point, int, Vector2d>(0, 0) { } -Point::Point(int x, int y) : PointBase<Point, int>(x, y) { +Point::Point(int x, int y) : PointBase<Point, int, Vector2d>(x, y) { } #if defined(OS_WIN) -Point::Point(DWORD point) : PointBase<Point, int>(0, 0){ +Point::Point(DWORD point) : PointBase<Point, int, Vector2d>(0, 0){ POINTS points = MAKEPOINTS(point); set_x(points.x); set_y(points.y); } -Point::Point(const POINT& point) : PointBase<Point, int>(point.x, point.y) { +Point::Point(const POINT& point) + : PointBase<Point, int, Vector2d>(point.x, point.y) { } Point& Point::operator=(const POINT& point) { @@ -43,7 +44,8 @@ POINT Point::ToPOINT() const { return p; } #elif defined(OS_MACOSX) -Point::Point(const CGPoint& point) : PointBase<Point, int>(point.x, point.y) { +Point::Point(const CGPoint& point) + : PointBase<Point, int, Vector2d>(point.x, point.y) { } CGPoint Point::ToCGPoint() const { diff --git a/ui/gfx/point.h b/ui/gfx/point.h index 5984d74..2e476d0 100644 --- a/ui/gfx/point.h +++ b/ui/gfx/point.h @@ -8,6 +8,7 @@ #include "ui/base/ui_export.h" #include "ui/gfx/point_base.h" #include "ui/gfx/point_f.h" +#include "ui/gfx/vector2d.h" #if defined(OS_WIN) typedef unsigned long DWORD; @@ -21,7 +22,7 @@ typedef struct tagPOINT POINT; namespace gfx { // A point has an x and y coordinate. -class UI_EXPORT Point : public PointBase<Point, int> { +class UI_EXPORT Point : public PointBase<Point, int, Vector2d> { public: Point(); Point(int x, int y); @@ -68,16 +69,24 @@ inline bool operator!=(const Point& lhs, const Point& rhs) { return !(lhs == rhs); } -inline Point operator+(Point lhs, Point rhs) { +inline Point operator+(const Point& lhs, const Vector2d& rhs) { return lhs.Add(rhs); } -inline Point operator-(Point lhs, Point rhs) { +inline Point operator-(const Point& lhs, const Vector2d& rhs) { return lhs.Subtract(rhs); } +inline Vector2d operator-(const Point& lhs, const Point& rhs) { + return lhs.OffsetFrom(rhs); +} + +inline Point PointAtOffsetFromOrigin(const Vector2d& offset_from_origin) { + return Point(offset_from_origin.x(), offset_from_origin.y()); +} + #if !defined(COMPILER_MSVC) -extern template class PointBase<Point, int>; +extern template class PointBase<Point, int, Vector2d>; #endif } // namespace gfx diff --git a/ui/gfx/point_base.h b/ui/gfx/point_base.h index 34e32f5..acaefe1 100644 --- a/ui/gfx/point_base.h +++ b/ui/gfx/point_base.h @@ -14,7 +14,7 @@ namespace gfx { // A point has an x and y coordinate. -template<typename Class, typename Type> +template<typename Class, typename Type, typename VectorClass> class UI_EXPORT PointBase { public: Type x() const { return x_; } @@ -33,17 +33,25 @@ class UI_EXPORT PointBase { y_ += delta_y; } - Class Add(const Class& other) const WARN_UNUSED_RESULT { + void operator+=(const VectorClass& other) { + Offset(other.x(), other.y()); + } + + void operator-=(const VectorClass& other) { + Offset(-other.x(), -other.y()); + } + + Class Add(const VectorClass& other) const WARN_UNUSED_RESULT { const Class* orig = static_cast<const Class*>(this); Class copy = *orig; - copy.Offset(other.x_, other.y_); + copy.Offset(other.x(), other.y()); return copy; } - Class Subtract(const Class& other) const WARN_UNUSED_RESULT { + Class Subtract(const VectorClass& other) const WARN_UNUSED_RESULT { const Class* orig = static_cast<const Class*>(this); Class copy = *orig; - copy.Offset(-other.x_, -other.y_); + copy.Offset(-other.x(), -other.y()); return copy; } @@ -55,6 +63,14 @@ class UI_EXPORT PointBase { return x_ == 0 && y_ == 0; } + VectorClass OffsetFromOrigin() const { + return VectorClass(x_, y_); + } + + VectorClass OffsetFrom(const Class& other) const { + return VectorClass(x_ - other.x_, y_ - other.y_); + } + // A point is less than another point if its y-value is closer // to the origin. If the y-values are the same, then point with // the x-value closer to the origin is considered less than the diff --git a/ui/gfx/point_f.cc b/ui/gfx/point_f.cc index 3d814c5..d22693a0 100644 --- a/ui/gfx/point_f.cc +++ b/ui/gfx/point_f.cc @@ -8,12 +8,12 @@ namespace gfx { -template class PointBase<PointF, float>; +template class PointBase<PointF, float, Vector2dF>; -PointF::PointF() : PointBase<PointF, float>(0, 0) { +PointF::PointF() : PointBase<PointF, float, Vector2dF>(0, 0) { } -PointF::PointF(float x, float y) : PointBase<PointF, float>(x, y) { +PointF::PointF(float x, float y) : PointBase<PointF, float, Vector2dF>(x, y) { } PointF::~PointF() {} diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h index d6cded9..3e69bd7 100644 --- a/ui/gfx/point_f.h +++ b/ui/gfx/point_f.h @@ -9,11 +9,12 @@ #include "ui/base/ui_export.h" #include "ui/gfx/point_base.h" +#include "ui/gfx/vector2d_f.h" namespace gfx { // A floating version of gfx::Point. -class UI_EXPORT PointF : public PointBase<PointF, float> { +class UI_EXPORT PointF : public PointBase<PointF, float, Vector2dF> { public: PointF(); PointF(float x, float y); @@ -39,16 +40,24 @@ inline bool operator!=(const PointF& lhs, const PointF& rhs) { return !(lhs == rhs); } -inline PointF operator+(PointF lhs, PointF rhs) { +inline PointF operator+(const PointF& lhs, const Vector2dF& rhs) { return lhs.Add(rhs); } -inline PointF operator-(PointF lhs, PointF rhs) { +inline PointF operator-(const PointF& lhs, const Vector2dF& rhs) { return lhs.Subtract(rhs); } +inline Vector2dF operator-(const PointF& lhs, const PointF& rhs) { + return lhs.OffsetFrom(rhs); +} + +inline PointF PointAtOffsetFromOrigin(const Vector2dF& offset_from_origin) { + return PointF(offset_from_origin.x(), offset_from_origin.y()); +} + #if !defined(COMPILER_MSVC) -extern template class PointBase<PointF, float>; +extern template class PointBase<PointF, float, Vector2dF>; #endif } // namespace gfx diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc index cae2166..ea42b53 100644 --- a/ui/gfx/point_unittest.cc +++ b/ui/gfx/point_unittest.cc @@ -4,6 +4,7 @@ #include "ui/gfx/point_base.h" +#include "base/basictypes.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/point.h" #include "ui/gfx/point_f.h" @@ -47,4 +48,36 @@ TEST(PointTest, IsOrigin) { EXPECT_TRUE(gfx::PointF(0, 0).IsOrigin()); } +TEST(PointTest, VectorArithmetic) { + gfx::Point a(1, 5); + gfx::Vector2d v1(3, -3); + gfx::Vector2d v2(-8, 1); + + static const struct { + gfx::Point expected; + gfx::Point actual; + } tests[] = { + { gfx::Point(4, 2), a + v1 }, + { gfx::Point(-2, 8), a - v1 }, + { a, a - v1 + v1 }, + { a, a + v1 - v1 }, + { a, a + gfx::Vector2d() }, + { gfx::Point(12, 1), a + v1 - v2 }, + { gfx::Point(-10, 9), a - v1 + v2 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) + EXPECT_EQ(tests[i].expected.ToString(), + tests[i].actual.ToString()); +} + +TEST(PointTest, OffsetFromPoint) { + gfx::Point a(1, 5); + gfx::Point b(-20, 8); + EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(), + b.OffsetFrom(a).ToString()); + EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(), + (b - a).ToString()); +} + } // namespace ui diff --git a/ui/gfx/rect.cc b/ui/gfx/rect.cc index 551e6f6..b01d60c 100644 --- a/ui/gfx/rect.cc +++ b/ui/gfx/rect.cc @@ -17,9 +17,9 @@ namespace gfx { -template class RectBase<Rect, Point, Size, Insets, int>; +template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; -typedef class RectBase<Rect, Point, Size, Insets, int> RectBaseT; +typedef class RectBase<Rect, Point, Size, Insets, Vector2d, int> RectBaseT; Rect::Rect() : RectBaseT(gfx::Point()) { } diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h index bf56896..9138f46 100644 --- a/ui/gfx/rect.h +++ b/ui/gfx/rect.h @@ -18,6 +18,7 @@ #include "ui/gfx/rect_base.h" #include "ui/gfx/rect_f.h" #include "ui/gfx/size.h" +#include "ui/gfx/vector2d.h" #if defined(OS_WIN) typedef struct tagRECT RECT; @@ -33,7 +34,8 @@ namespace gfx { class Insets; -class UI_EXPORT Rect : public RectBase<Rect, Point, Size, Insets, int> { +class UI_EXPORT Rect + : public RectBase<Rect, Point, Size, Insets, Vector2d, int> { public: Rect(); Rect(int width, int height); @@ -80,7 +82,7 @@ UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b); UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); #if !defined(COMPILER_MSVC) -extern template class RectBase<Rect, Point, Size, Insets, int>; +extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; #endif } // namespace gfx diff --git a/ui/gfx/rect_base.h b/ui/gfx/rect_base.h index a9ddda4..0a3298c 100644 --- a/ui/gfx/rect_base.h +++ b/ui/gfx/rect_base.h @@ -22,6 +22,7 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> class UI_EXPORT RectBase { public: @@ -46,6 +47,10 @@ class UI_EXPORT RectBase { Type right() const { return x() + width(); } Type bottom() const { return y() + height(); } + VectorClass OffsetFromOrigin() const { + return VectorClass(x(), y()); + } + void SetRect(Type x, Type y, Type width, Type height); // Shrink the rectangle by a horizontal and vertical distance on all sides. @@ -61,8 +66,8 @@ class UI_EXPORT RectBase { // Move the rectangle by a horizontal and vertical distance. void Offset(Type horizontal, Type vertical); - void Offset(const PointClass& point) { - Offset(point.x(), point.y()); + void Offset(const VectorClass& distance) { + Offset(distance.x(), distance.y()); } InsetsClass InsetsFrom(const Class& inner) const { diff --git a/ui/gfx/rect_base_impl.h b/ui/gfx/rect_base_impl.h index 291929d..5ca9afa 100644 --- a/ui/gfx/rect_base_impl.h +++ b/ui/gfx/rect_base_impl.h @@ -32,9 +32,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::RectBase( - const PointClass& origin, const SizeClass& size) +RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + RectBase(const PointClass& origin, const SizeClass& size) : origin_(origin), size_(size) { } @@ -42,9 +43,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::RectBase( - const SizeClass& size) +RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + RectBase(const SizeClass& size) : size_(size) { } @@ -52,9 +54,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::RectBase( - const PointClass& origin) +RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + RectBase(const PointClass& origin) : origin_(origin) { } @@ -62,16 +65,19 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::~RectBase() {} +RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + ~RectBase() {} template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::SetRect( - Type x, Type y, Type width, Type height) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + SetRect(Type x, Type y, Type width, Type height) { origin_.SetPoint(x, y); set_width(width); set_height(height); @@ -81,9 +87,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Inset( - const InsetsClass& insets) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Inset(const InsetsClass& insets) { Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); } @@ -91,9 +98,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Inset( - Type left, Type top, Type right, Type bottom) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Inset(Type left, Type top, Type right, Type bottom) { Offset(left, top); set_width(std::max(width() - left - right, static_cast<Type>(0))); set_height(std::max(height() - top - bottom, static_cast<Type>(0))); @@ -103,9 +111,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Offset( - Type horizontal, Type vertical) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Offset(Type horizontal, Type vertical) { origin_.Offset(horizontal, vertical); } @@ -113,9 +122,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::operator<( - const Class& other) const { +bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + operator<(const Class& other) const { if (origin_ == other.origin_) { if (width() == other.width()) { return height() < other.height(); @@ -131,9 +141,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Contains( - Type point_x, Type point_y) const { +bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Contains(Type point_x, Type point_y) const { return (point_x >= x()) && (point_x < right()) && (point_y >= y()) && (point_y < bottom()); } @@ -142,9 +153,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Contains( - const Class& rect) const { +bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Contains(const Class& rect) const { return (rect.x() >= x() && rect.right() <= right() && rect.y() >= y() && rect.bottom() <= bottom()); } @@ -153,9 +165,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Intersects( - const Class& rect) const { +bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Intersects(const Class& rect) const { return !(rect.x() >= right() || rect.right() <= x() || rect.y() >= bottom() || rect.bottom() <= y()); } @@ -164,9 +177,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Intersect( - const Class& rect) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Intersect(const Class& rect) { if (IsEmpty() || rect.IsEmpty()) { SetRect(0, 0, 0, 0); return; @@ -187,9 +201,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Union( - const Class& rect) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Union(const Class& rect) { if (IsEmpty()) { *this = rect; return; @@ -209,9 +224,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::Subtract( - const Class& rect) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + Subtract(const Class& rect) { if (!Intersects(rect)) return; if (rect.Contains(*static_cast<const Class*>(this))) { @@ -246,9 +262,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::AdjustToFit( - const Class& rect) { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + AdjustToFit(const Class& rect) { Type new_x = x(); Type new_y = y(); Type new_width = width(); @@ -262,9 +279,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -PointClass RectBase<Class, PointClass, SizeClass, InsetsClass, Type>:: - CenterPoint() const { +PointClass RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, + Type>::CenterPoint() const { return PointClass(x() + width() / 2, y() + height() / 2); } @@ -272,8 +290,9 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>:: +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: ClampToCenteredSize(const SizeClass& size) { Type new_width = std::min(width(), size.width()); Type new_height = std::min(height(), size.height()); @@ -286,9 +305,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -void RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::SplitVertically( - Class* left_half, Class* right_half) const { +void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + SplitVertically(Class* left_half, Class* right_half) const { DCHECK(left_half); DCHECK(right_half); @@ -303,9 +323,10 @@ template<typename Class, typename PointClass, typename SizeClass, typename InsetsClass, + typename VectorClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::SharesEdgeWith( - const Class& rect) const { +bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: + SharesEdgeWith(const Class& rect) const { return (y() == rect.y() && height() == rect.height() && (x() == rect.right() || right() == rect.x())) || (x() == rect.x() && width() == rect.width() && diff --git a/ui/gfx/rect_f.cc b/ui/gfx/rect_f.cc index 6035391..f011d71 100644 --- a/ui/gfx/rect_f.cc +++ b/ui/gfx/rect_f.cc @@ -11,9 +11,10 @@ namespace gfx { -template class RectBase<RectF, PointF, SizeF, InsetsF, float>; +template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>; -typedef class RectBase<RectF, PointF, SizeF, InsetsF, float> RectBaseT; +typedef class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, + float> RectBaseT; RectF::RectF() : RectBaseT(gfx::SizeF()) { } diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h index 8439eb1..db00324 100644 --- a/ui/gfx/rect_f.h +++ b/ui/gfx/rect_f.h @@ -10,13 +10,15 @@ #include "ui/gfx/point_f.h" #include "ui/gfx/rect_base.h" #include "ui/gfx/size_f.h" +#include "ui/gfx/vector2d_f.h" namespace gfx { class InsetsF; // A floating version of gfx::Rect. -class UI_EXPORT RectF : public RectBase<RectF, PointF, SizeF, InsetsF, float> { +class UI_EXPORT RectF + : public RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float> { public: RectF(); RectF(float width, float height); @@ -59,7 +61,7 @@ inline RectF ScaleRect(const RectF& r, float scale) { } #if !defined(COMPILER_MSVC) -extern template class RectBase<RectF, PointF, SizeF, InsetsF, float>; +extern template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>; #endif } // namespace gfx diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index a8246c2..dfbc3a4 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -406,7 +406,7 @@ void RenderText::SetText(const string16& text) { void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { if (horizontal_alignment_ != alignment) { horizontal_alignment_ = alignment; - display_offset_ = Point(); + display_offset_ = Vector2d(); cached_bounds_and_offset_valid_ = false; } } @@ -765,7 +765,7 @@ RenderText::RenderText() cached_bounds_and_offset_valid_(false) { } -const Point& RenderText::GetUpdatedDisplayOffset() { +const Vector2d& RenderText::GetUpdatedDisplayOffset() { UpdateCachedBoundsAndOffset(); return display_offset_; } @@ -839,41 +839,39 @@ void RenderText::ApplyCompositionAndSelectionStyles( } } -Point RenderText::GetTextOrigin() { - Point origin = display_rect().origin(); - origin = origin.Add(GetUpdatedDisplayOffset()); - origin = origin.Add(GetAlignmentOffset()); - return origin; +Vector2d RenderText::GetTextOffset() { + Vector2d offset = display_rect().OffsetFromOrigin(); + offset.Add(GetUpdatedDisplayOffset()); + offset.Add(GetAlignmentOffset()); + return offset; } Point RenderText::ToTextPoint(const Point& point) { - return point.Subtract(GetTextOrigin()); + return point.Subtract(GetTextOffset()); } Point RenderText::ToViewPoint(const Point& point) { - return point.Add(GetTextOrigin()); + return point.Add(GetTextOffset()); } int RenderText::GetContentWidth() { return GetStringSize().width() + (cursor_enabled_ ? 1 : 0); } -Point RenderText::GetAlignmentOffset() { - if (horizontal_alignment() != ALIGN_LEFT) { - int x_offset = display_rect().width() - GetContentWidth(); - if (horizontal_alignment() == ALIGN_CENTER) - x_offset /= 2; - return Point(x_offset, 0); - } - return Point(); +Vector2d RenderText::GetAlignmentOffset() { + if (horizontal_alignment() == ALIGN_LEFT) + return Vector2d(); + + int x_offset = display_rect().width() - GetContentWidth(); + if (horizontal_alignment() == ALIGN_CENTER) + x_offset /= 2; + return Vector2d(x_offset, 0); } Point RenderText::GetOriginForDrawing() { - Point origin(GetTextOrigin()); - const int height = GetStringSize().height(); // Center the text vertically in the display area. - origin.Offset(0, (display_rect().height() - height) / 2); - return origin; + return gfx::PointAtOffsetFromOrigin(GetTextOffset()) + + Vector2d(0, (display_rect().height() - GetStringSize().height()) / 2); } void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { @@ -974,35 +972,37 @@ void RenderText::UpdateCachedBoundsAndOffset() { const int display_width = display_rect_.width(); const int content_width = GetContentWidth(); - int delta_offset = 0; + int delta_x = 0; if (content_width <= display_width || !cursor_enabled()) { // Don't pan if the text fits in the display width or when the cursor is // disabled. - delta_offset = -display_offset_.x(); + delta_x = -display_offset_.x(); } else if (cursor_bounds_.right() >= display_rect_.right()) { // TODO(xji): when the character overflow is a RTL character, currently, if // we pan cursor at the rightmost position, the entered RTL character is not // displayed. Should pan cursor to show the last logical characters. // // Pan to show the cursor when it overflows to the right, - delta_offset = display_rect_.right() - cursor_bounds_.right() - 1; + delta_x = display_rect_.right() - cursor_bounds_.right() - 1; } else if (cursor_bounds_.x() < display_rect_.x()) { // TODO(xji): have similar problem as above when overflow character is a // LTR character. // // Pan to show the cursor when it overflows to the left. - delta_offset = display_rect_.x() - cursor_bounds_.x(); + delta_x = display_rect_.x() - cursor_bounds_.x(); } else if (display_offset_.x() != 0) { // Reduce the pan offset to show additional overflow text when the display // width increases. const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; const int offset = negate_rtl * display_offset_.x(); - if (display_width > (content_width + offset)) - delta_offset = negate_rtl * (display_width - (content_width + offset)); + if (display_width > (content_width + offset)) { + delta_x = negate_rtl * (display_width - (content_width + offset)); + } } - display_offset_.Offset(delta_offset, 0); - cursor_bounds_.Offset(delta_offset, 0); + gfx::Vector2d delta_offset(delta_x, 0); + display_offset_ += delta_offset; + cursor_bounds_.Offset(delta_offset); } void RenderText::DrawSelection(Canvas* canvas) { diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index 3ba9f87..13215d8 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -24,6 +24,7 @@ #include "ui/gfx/selection_model.h" #include "ui/gfx/shadow_value.h" #include "ui/gfx/text_constants.h" +#include "ui/gfx/vector2d.h" class SkCanvas; class SkDrawLooper; @@ -294,7 +295,7 @@ class UI_EXPORT RenderText { protected: RenderText(); - const Point& GetUpdatedDisplayOffset(); + const Vector2d& GetUpdatedDisplayOffset(); void set_cached_bounds_and_offset_valid(bool valid) { cached_bounds_and_offset_valid_ = valid; @@ -367,8 +368,9 @@ class UI_EXPORT RenderText { // style (foreground) to selection range. void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); - // Returns the text origin after applying text alignment and display offset. - Point GetTextOrigin(); + // Returns the text offset from the origin after applying text alignment and + // display offset. + Vector2d GetTextOffset(); // Convert points from the text space to the view space and back. // Handles the display area, display offset, and the application LTR/RTL mode. @@ -380,7 +382,7 @@ class UI_EXPORT RenderText { int GetContentWidth(); // Returns display offset based on current text alignment. - Point GetAlignmentOffset(); + Vector2d GetAlignmentOffset(); // Returns the origin point for drawing text. Does not account for font // baseline, as needed by Skia. @@ -504,7 +506,7 @@ class UI_EXPORT RenderText { // The offset for the text to be drawn, relative to the display area. // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). - Point display_offset_; + Vector2d display_offset_; // The cached bounds and offset are invalidated by changes to the cursor, // selection, font, and other operations that adjust the visible text bounds. diff --git a/ui/gfx/render_text_mac.cc b/ui/gfx/render_text_mac.cc index 9ee069f..75d7f42 100644 --- a/ui/gfx/render_text_mac.cc +++ b/ui/gfx/render_text_mac.cc @@ -232,13 +232,12 @@ void RenderTextMac::ComputeRuns() { CFArrayRef ct_runs = CTLineGetGlyphRuns(line_); const CFIndex ct_runs_count = CFArrayGetCount(ct_runs); - Point offset(GetTextOrigin()); - // Skia will draw glyphs with respect to the baseline. - offset.Offset(0, common_baseline_); + gfx::Vector2d text_offset = GetTextOffset(); - const SkScalar x = SkIntToScalar(offset.x()); - const SkScalar y = SkIntToScalar(offset.y()); - SkPoint run_origin = SkPoint::Make(offset.x(), offset.y()); + // Skia will draw glyphs with respect to the baseline. + const SkScalar x = SkIntToScalar(text_offset.x()); + const SkScalar y = SkIntToScalar(text_offset.y() + common_baseline_); + SkPoint run_origin = SkPoint::Make(x, y); const CFRange empty_cf_range = CFRangeMake(0, 0); for (CFIndex i = 0; i < ct_runs_count; ++i) { diff --git a/ui/gfx/vector2d.cc b/ui/gfx/vector2d.cc new file mode 100644 index 0000000..a1492cb --- /dev/null +++ b/ui/gfx/vector2d.cc @@ -0,0 +1,45 @@ +// 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. + +#include "ui/gfx/vector2d.h" + +#include <cmath> + +#include "base/stringprintf.h" + +namespace gfx { + +Vector2d::Vector2d() : x_(0), y_(0) { +} + +Vector2d::Vector2d(int x, int y) : x_(x), y_(y) { +} + +bool Vector2d::IsZero() const { + return x_ == 0 && y_ == 0; +} + +void Vector2d::Add(const Vector2d& other) { + x_ += other.x_; + y_ += other.y_; +} + +void Vector2d::Subtract(const Vector2d& other) { + x_ -= other.x_; + y_ -= other.y_; +} + +int64 Vector2d::LengthSquared() const { + return static_cast<int64>(x_) * x_ + static_cast<int64>(y_) * y_; +} + +float Vector2d::Length() const { + return static_cast<float>(std::sqrt(static_cast<double>(LengthSquared()))); +} + +std::string Vector2d::ToString() const { + return base::StringPrintf("[%d %d]", x_, y_); +} + +} // namespace gfx diff --git a/ui/gfx/vector2d.h b/ui/gfx/vector2d.h new file mode 100644 index 0000000..6ec3708 --- /dev/null +++ b/ui/gfx/vector2d.h @@ -0,0 +1,81 @@ +// 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. + +// Defines a simple integer vector class. This class is used to indicate a +// distance in two dimensions between two points. Subtracting two points should +// produce a vector, and adding a vector to a point produces the point at the +// vector's distance from the original point. + +#ifndef UI_GFX_VECTOR2D_H_ +#define UI_GFX_VECTOR2D_H_ + +#include <string> + +#include "base/basictypes.h" +#include "ui/base/ui_export.h" +#include "ui/gfx/vector2d_f.h" + +namespace gfx { + +class UI_EXPORT Vector2d { + public: + Vector2d(); + Vector2d(int x, int y); + + int x() const { return x_; } + void set_x(int x) { x_ = x; } + + int y() const { return y_; } + void set_y(int y) { y_ = y; } + + // True if both components of the vector are 0. + bool IsZero() const; + + // Add the components of the |other| vector to the current vector. + void Add(const Vector2d& other); + // Subtract the components of the |other| vector from the current vector. + void Subtract(const Vector2d& other); + + void operator+=(const Vector2d& other) { Add(other); } + void operator-=(const Vector2d& other) { Subtract(other); } + + // Gives the square of the diagonal length of the vector. Since this is + // cheaper to compute than Length(), it is useful when you want to compare + // relative lengths of different vectors without needing the actual lengths. + int64 LengthSquared() const; + // Gives the diagonal length of the vector. + float Length() const; + + std::string ToString() const; + + operator Vector2dF() const { return Vector2dF(x_, y_); } + + private: + int x_; + int y_; +}; + +inline bool operator==(const Vector2d& lhs, const Vector2d& rhs) { + return lhs.x() == rhs.x() && lhs.y() == rhs.y(); +} + +inline Vector2d operator-(const Vector2d& v) { + return Vector2d(-v.x(), -v.y()); +} + +inline Vector2d operator+(const Vector2d& lhs, const Vector2d& rhs) { + Vector2d result = lhs; + result.Add(rhs); + return result; +} + +inline Vector2d operator-(const Vector2d& lhs, const Vector2d& rhs) { + Vector2d result = lhs; + result.Add(-rhs); + return result; +} + +} // namespace gfx + +#endif // UI_GFX_VECTOR2D_H_ diff --git a/ui/gfx/vector2d_conversions.cc b/ui/gfx/vector2d_conversions.cc new file mode 100644 index 0000000..457e9f7 --- /dev/null +++ b/ui/gfx/vector2d_conversions.cc @@ -0,0 +1,30 @@ +// 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. + +#include "ui/gfx/vector2d_conversions.h" + +#include "ui/gfx/safe_integer_conversions.h" + +namespace gfx { + +Vector2d ToFlooredVector2d(const Vector2dF& vector2d) { + int x = ToFlooredInt(vector2d.x()); + int y = ToFlooredInt(vector2d.y()); + return Vector2d(x, y); +} + +Vector2d ToCeiledVector2d(const Vector2dF& vector2d) { + int x = ToCeiledInt(vector2d.x()); + int y = ToCeiledInt(vector2d.y()); + return Vector2d(x, y); +} + +Vector2d ToRoundedVector2d(const Vector2dF& vector2d) { + int x = ToRoundedInt(vector2d.x()); + int y = ToRoundedInt(vector2d.y()); + return Vector2d(x, y); +} + +} // namespace gfx + diff --git a/ui/gfx/vector2d_conversions.h b/ui/gfx/vector2d_conversions.h new file mode 100644 index 0000000..051092e --- /dev/null +++ b/ui/gfx/vector2d_conversions.h @@ -0,0 +1,24 @@ +// 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 UI_GFX_VECTOR2D_CONVERSIONS_H_ +#define UI_GFX_VECTOR2D_CONVERSIONS_H_ + +#include "ui/gfx/vector2d.h" +#include "ui/gfx/vector2d_f.h" + +namespace gfx { + +// Returns a Vector2d with each component from the input Vector2dF floored. +UI_EXPORT Vector2d ToFlooredVector2d(const Vector2dF& vector2d); + +// Returns a Vector2d with each component from the input Vector2dF ceiled. +UI_EXPORT Vector2d ToCeiledVector2d(const Vector2dF& vector2d); + +// Returns a Vector2d with each component from the input Vector2dF rounded. +UI_EXPORT Vector2d ToRoundedVector2d(const Vector2dF& vector2d); + +} // namespace gfx + +#endif // UI_GFX_VECTOR2D_CONVERSIONS_H_ diff --git a/ui/gfx/vector2d_f.cc b/ui/gfx/vector2d_f.cc new file mode 100644 index 0000000..f628421 --- /dev/null +++ b/ui/gfx/vector2d_f.cc @@ -0,0 +1,54 @@ +// 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. + +#include "ui/gfx/vector2d_f.h" + +#include <cmath> + +#include "base/stringprintf.h" + +namespace gfx { + +Vector2dF::Vector2dF() + : x_(0), + y_(0) { +} + +Vector2dF::Vector2dF(float x, float y) + : x_(x), + y_(y) { +} + +std::string Vector2dF::ToString() const { + return base::StringPrintf("[%f %f]", x_, y_); +} + +bool Vector2dF::IsZero() const { + return x_ == 0 && y_ == 0; +} + +void Vector2dF::Add(const Vector2dF& other) { + x_ += other.x_; + y_ += other.y_; +} + +void Vector2dF::Subtract(const Vector2dF& other) { + x_ -= other.x_; + y_ -= other.y_; +} + +double Vector2dF::LengthSquared() const { + return static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_; +} + +float Vector2dF::Length() const { + return static_cast<float>(std::sqrt(LengthSquared())); +} + +void Vector2dF::Scale(float x_scale, float y_scale) { + x_ *= x_scale; + y_ *= y_scale; +} + +} // namespace gfx diff --git a/ui/gfx/vector2d_f.h b/ui/gfx/vector2d_f.h new file mode 100644 index 0000000..e2baa0c --- /dev/null +++ b/ui/gfx/vector2d_f.h @@ -0,0 +1,81 @@ +// 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. + +// Defines a simple float vector class. This class is used to indicate a +// distance in two dimensions between two points. Subtracting two points should +// produce a vector, and adding a vector to a point produces the point at the +// vector's distance from the original point. + +#ifndef UI_GFX_VECTOR2D_F_H_ +#define UI_GFX_VECTOR2D_F_H_ + +#include <string> + +#include "ui/base/ui_export.h" + +namespace gfx { + +class UI_EXPORT Vector2dF { + public: + Vector2dF(); + Vector2dF(float x, float y); + + float x() const { return x_; } + void set_x(float x) { x_ = x; } + + float y() const { return y_; } + void set_y(float y) { y_ = y; } + + // True if both components of the vector are 0. + bool IsZero() const; + + // Add the components of the |other| vector to the current vector. + void Add(const Vector2dF& other); + // Subtract the components of the |other| vector from the current vector. + void Subtract(const Vector2dF& other); + + void operator+=(const Vector2dF& other) { Add(other); } + void operator-=(const Vector2dF& other) { Subtract(other); } + + // Gives the square of the diagonal length of the vector. + double LengthSquared() const; + // Gives the diagonal length of the vector. + float Length() const; + + // Scale the x and y components of the vector by |scale|. + void Scale(float scale) { Scale(scale, scale); } + // Scale the x and y components of the vector by |x_scale| and |y_scale| + // respectively. + void Scale(float x_scale, float y_scale); + + std::string ToString() const; + + private: + float x_; + float y_; +}; + +inline bool operator==(const Vector2dF& lhs, const Vector2dF& rhs) { + return lhs.x() == rhs.x() && lhs.y() == rhs.y(); +} + +inline Vector2dF operator-(const Vector2dF& v) { + return Vector2dF(-v.x(), -v.y()); +} + +inline Vector2dF operator+(const Vector2dF& lhs, const Vector2dF& rhs) { + Vector2dF result = lhs; + result.Add(rhs); + return result; +} + +inline Vector2dF operator-(const Vector2dF& lhs, const Vector2dF& rhs) { + Vector2dF result = lhs; + result.Add(-rhs); + return result; +} + +} // namespace gfx + +#endif // UI_GFX_VECTOR2D_F_H_ diff --git a/ui/gfx/vector2d_unittest.cc b/ui/gfx/vector2d_unittest.cc new file mode 100644 index 0000000..3dfbdf9 --- /dev/null +++ b/ui/gfx/vector2d_unittest.cc @@ -0,0 +1,186 @@ +// 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. + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/vector2d.h" +#include "ui/gfx/vector2d_f.h" + +#include <cmath> +#include <limits> + +namespace gfx { + +TEST(Vector2dTest, ConversionToFloat) { + gfx::Vector2d i(3, 4); + gfx::Vector2dF f = i; + EXPECT_EQ(i, f); +} + +TEST(Vector2dTest, IsZero) { + gfx::Vector2d int_zero(0, 0); + gfx::Vector2d int_nonzero(2, -2); + gfx::Vector2dF float_zero(0, 0); + gfx::Vector2dF float_nonzero(0.1f, -0.1f); + + EXPECT_TRUE(int_zero.IsZero()); + EXPECT_FALSE(int_nonzero.IsZero()); + EXPECT_TRUE(float_zero.IsZero()); + EXPECT_FALSE(float_nonzero.IsZero()); +} + +TEST(Vector2dTest, Add) { + gfx::Vector2d i1(3, 5); + gfx::Vector2d i2(4, -1); + + const struct { + gfx::Vector2d expected; + gfx::Vector2d actual; + } int_tests[] = { + { gfx::Vector2d(3, 5), i1 + gfx::Vector2d() }, + { gfx::Vector2d(3 + 4, 5 - 1), i1 + i2 }, + { gfx::Vector2d(3 - 4, 5 + 1), i1 - i2 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_tests); ++i) + EXPECT_EQ(int_tests[i].expected.ToString(), + int_tests[i].actual.ToString()); + + gfx::Vector2dF f1(3.1f, 5.1f); + gfx::Vector2dF f2(4.3f, -1.3f); + + const struct { + gfx::Vector2dF expected; + gfx::Vector2dF actual; + } float_tests[] = { + { gfx::Vector2dF(3.1F, 5.1F), f1 + gfx::Vector2d() }, + { gfx::Vector2dF(3.1F, 5.1F), f1 + gfx::Vector2dF() }, + { gfx::Vector2dF(3.1f + 4.3f, 5.1f - 1.3f), f1 + f2 }, + { gfx::Vector2dF(3.1f - 4.3f, 5.1f + 1.3f), f1 - f2 } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) + EXPECT_EQ(float_tests[i].expected.ToString(), + float_tests[i].actual.ToString()); +} + +TEST(Vector2dTest, Negative) { + const struct { + gfx::Vector2d expected; + gfx::Vector2d actual; + } int_tests[] = { + { gfx::Vector2d(0, 0), -gfx::Vector2d(0, 0) }, + { gfx::Vector2d(-3, -3), -gfx::Vector2d(3, 3) }, + { gfx::Vector2d(3, 3), -gfx::Vector2d(-3, -3) }, + { gfx::Vector2d(-3, 3), -gfx::Vector2d(3, -3) }, + { gfx::Vector2d(3, -3), -gfx::Vector2d(-3, 3) } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_tests); ++i) + EXPECT_EQ(int_tests[i].expected.ToString(), + int_tests[i].actual.ToString()); + + const struct { + gfx::Vector2dF expected; + gfx::Vector2dF actual; + } float_tests[] = { + { gfx::Vector2dF(0, 0), -gfx::Vector2d(0, 0) }, + { gfx::Vector2dF(-0.3f, -0.3f), -gfx::Vector2dF(0.3f, 0.3f) }, + { gfx::Vector2dF(0.3f, 0.3f), -gfx::Vector2dF(-0.3f, -0.3f) }, + { gfx::Vector2dF(-0.3f, 0.3f), -gfx::Vector2dF(0.3f, -0.3f) }, + { gfx::Vector2dF(0.3f, -0.3f), -gfx::Vector2dF(-0.3f, 0.3f) } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) + EXPECT_EQ(float_tests[i].expected.ToString(), + float_tests[i].actual.ToString()); +} + +TEST(Vector2dTest, Scale) { + float double_values[][4] = { + { 4.5f, 1.2f, 3.3f, 5.6f }, + { 4.5f, -1.2f, 3.3f, 5.6f }, + { 4.5f, 1.2f, 3.3f, -5.6f }, + { 4.5f, 1.2f, -3.3f, -5.6f }, + { -4.5f, 1.2f, 3.3f, 5.6f }, + { -4.5f, 1.2f, 0, 5.6f }, + { -4.5f, 1.2f, 3.3f, 0 }, + { 4.5f, 0, 3.3f, 5.6f }, + { 0, 1.2f, 3.3f, 5.6f } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(double_values); ++i) { + gfx::Vector2dF v(double_values[i][0], double_values[i][1]); + v.Scale(double_values[i][2], double_values[i][3]); + EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]); + EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]); + } + + float single_values[][3] = { + { 4.5f, 1.2f, 3.3f }, + { 4.5f, -1.2f, 3.3f }, + { 4.5f, 1.2f, 3.3f }, + { 4.5f, 1.2f, -3.3f }, + { -4.5f, 1.2f, 3.3f }, + { -4.5f, 1.2f, 0 }, + { -4.5f, 1.2f, 3.3f }, + { 4.5f, 0, 3.3f }, + { 0, 1.2f, 3.3f } + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(single_values); ++i) { + gfx::Vector2dF v(single_values[i][0], single_values[i][1]); + v.Scale(single_values[i][2]); + EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]); + EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]); + } +} + +TEST(Vector2dTest, Length) { + int int_values[][2] = { + { 0, 0 }, + { 10, 20 }, + { 20, 10 }, + { -10, -20 }, + { -20, 10 }, + { 10, -20 }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_values); ++i) { + int v0 = int_values[i][0]; + int v1 = int_values[i][1]; + double length_squared = + static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; + double length = std::sqrt(length_squared); + gfx::Vector2d vector(v0, v1); + EXPECT_EQ(static_cast<float>(length_squared), vector.LengthSquared()); + EXPECT_EQ(static_cast<float>(length), vector.Length()); + } + + float float_values[][2] = { + { 0, 0 }, + { 10.5f, 20.5f }, + { 20.5f, 10.5f }, + { -10.5f, -20.5f }, + { -20.5f, 10.5f }, + { 10.5f, -20.5f }, + // A large vector that fails if the Length function doesn't use + // double precision internally. + { 1236278317862780234892374893213178027.12122348904204230f, + 335890352589839028212313231225425134332.38123f }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_values); ++i) { + double v0 = float_values[i][0]; + double v1 = float_values[i][1]; + double length_squared = + static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; + double length = std::sqrt(length_squared); + gfx::Vector2dF vector(v0, v1); + EXPECT_EQ(length_squared, vector.LengthSquared()); + EXPECT_EQ(static_cast<float>(length), vector.Length()); + } +} + +} // namespace ui @@ -511,6 +511,12 @@ 'gfx/transform.h', 'gfx/transform_util.cc', 'gfx/transform_util.h', + 'gfx/vector2d.cc', + 'gfx/vector2d.h', + 'gfx/vector2d_conversions.cc', + 'gfx/vector2d_conversions.h', + 'gfx/vector2d_f.cc', + 'gfx/vector2d_f.h', 'gfx/video_decode_acceleration_support_mac.h', 'gfx/video_decode_acceleration_support_mac.mm', 'ui_controls/ui_controls.h', diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index f371091..891df7a 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -88,6 +88,7 @@ 'gfx/size_unittest.cc', 'gfx/skbitmap_operations_unittest.cc', 'gfx/skia_util_unittest.cc', + 'gfx/vector2d_unittest.cc', 'test/run_all_unittests.cc', 'test/test_suite.cc', 'test/test_suite.h', diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_delegate.cc index eb47a90..f35e143 100644 --- a/ui/views/bubble/bubble_delegate.cc +++ b/ui/views/bubble/bubble_delegate.cc @@ -351,7 +351,8 @@ gfx::Rect BubbleDelegateView::GetBubbleBounds() { #if defined(OS_WIN) && !defined(USE_AURA) gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); - client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); + client_bounds.Offset( + border_widget_->GetWindowBoundsInScreen().OffsetFromOrigin()); return client_bounds; } #endif diff --git a/ui/views/button_drag_utils.cc b/ui/views/button_drag_utils.cc index 8bdfe94..c1b37b5 100644 --- a/ui/views/button_drag_utils.cc +++ b/ui/views/button_drag_utils.cc @@ -47,7 +47,7 @@ void SetURLAndDragImage(const GURL& url, views::GetCanvasForDragImage(widget, prefsize)); button.PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); drag_utils::SetDragImageOnDataObject(*canvas, prefsize, - gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); + gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2), data); } } // namespace button_drag_utils diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index 87eeca4..796b45f 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -450,10 +450,8 @@ void MenuController::OnMouseDragged(SubmenuView* source, return; if (possible_drag_) { - if (View::ExceededDragThreshold(event.x() - press_pt_.x(), - event.y() - press_pt_.y())) { + if (View::ExceededDragThreshold(event.location() - press_pt_)) StartDrag(source, press_pt_); - } return; } MenuItemView* mouse_menu = NULL; @@ -859,7 +857,8 @@ void MenuController::StartDrag(SubmenuView* source, OSExchangeData data; item->GetDelegate()->WriteDragData(item, &data); - drag_utils::SetDragImageOnDataObject(*canvas, item->size(), press_loc, + drag_utils::SetDragImageOnDataObject(*canvas, item->size(), + press_loc.OffsetFromOrigin(), &data); StopScrolling(); int drag_ops = item->GetDelegate()->GetDragOperations(item); diff --git a/ui/views/controls/menu/menu_image_util.cc b/ui/views/controls/menu/menu_image_util.cc index 02e6ae9..c4545087 100644 --- a/ui/views/controls/menu/menu_image_util.cc +++ b/ui/views/controls/menu/menu_image_util.cc @@ -43,7 +43,7 @@ class RadioButtonImageSource : public gfx::CanvasImageSource { virtual ~RadioButtonImageSource() {} virtual void Draw(gfx::Canvas* canvas) OVERRIDE { - canvas->Translate(gfx::Point(1, 1)); + canvas->Translate(gfx::Vector2d(1, 1)); SkPoint gradient_points[3]; gradient_points[0].iset(0, 0); diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc index c6e575f..140df74 100644 --- a/ui/views/controls/slider.cc +++ b/ui/views/controls/slider.cc @@ -199,7 +199,7 @@ void Slider::OnPaint(gfx::Canvas* canvas) { int middle = std::max(full, images_[LEFT]->width()); canvas->Save(); - canvas->Translate(gfx::Point(kBarInsetX, bar_cy)); + canvas->Translate(gfx::Vector2d(kBarInsetX, bar_cy)); canvas->DrawImageInt(*images_[LEFT], 0, 0); canvas->DrawImageInt(*images_[RIGHT], bar_width - images_[RIGHT]->width(), diff --git a/ui/views/controls/table/table_view_win.cc b/ui/views/controls/table/table_view_win.cc index 1538dd8..7ce46c0 100644 --- a/ui/views/controls/table/table_view_win.cc +++ b/ui/views/controls/table/table_view_win.cc @@ -517,7 +517,7 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window, static bool select_on_mouse_up = false; // If the mouse is down, this is the location of the mouse down message. - static int mouse_down_x, mouse_down_y; + CR_DEFINE_STATIC_LOCAL(gfx::Point, mouse_down_pos, ()); switch (message) { case WM_CONTEXTMENU: { @@ -647,8 +647,8 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window, table_view->ignore_listview_change_ = true; in_mouse_down = true; select_on_mouse_up = false; - mouse_down_x = GET_X_LPARAM(l_param); - mouse_down_y = GET_Y_LPARAM(l_param); + mouse_down_pos.set_x(GET_X_LPARAM(l_param)); + mouse_down_pos.set_y(GET_Y_LPARAM(l_param)); int model_index = table_view->ViewToModel(view_index); bool select = true; if (w_param & MK_CONTROL) { @@ -709,9 +709,8 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window, case WM_MOUSEMOVE: { if (in_mouse_down) { - int x = GET_X_LPARAM(l_param); - int y = GET_Y_LPARAM(l_param); - if (View::ExceededDragThreshold(x - mouse_down_x, y - mouse_down_y)) { + gfx::Point mouse_pos(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)); + if (View::ExceededDragThreshold(mouse_pos - mouse_down_pos)) { // We're about to start drag and drop, which results in no mouse up. // Release capture and reset state. ReleaseCapture(); diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 02e4c49..28ccdcb 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -112,8 +112,7 @@ bool NativeTextfieldViews::OnMousePressed(const ui::MouseEvent& event) { bool NativeTextfieldViews::ExceededDragThresholdFromLastClickLocation( const ui::MouseEvent& event) { - gfx::Point location_delta = event.location().Subtract(last_click_location_); - return ExceededDragThreshold(location_delta.x(), location_delta.y()); + return ExceededDragThreshold(event.location() - last_click_location_); } bool NativeTextfieldViews::OnMouseDragged(const ui::MouseEvent& event) { diff --git a/ui/views/painter.cc b/ui/views/painter.cc index 4275c54..99c537c 100644 --- a/ui/views/painter.cc +++ b/ui/views/painter.cc @@ -171,7 +171,7 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas, const gfx::Rect& rect) { DCHECK(canvas && painter); canvas->Save(); - canvas->Translate(rect.origin()); + canvas->Translate(rect.OffsetFromOrigin()); painter->Paint(canvas, rect.size()); canvas->Restore(); } diff --git a/ui/views/view.cc b/ui/views/view.cc index 660128b..8faa77b 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -624,7 +624,7 @@ void View::ConvertPointToTarget(const View* source, // API defines NULL |source| as returning the point in screen coordinates. if (!source) { *point = point->Subtract( - root->GetWidget()->GetClientAreaBoundsInScreen().origin()); + root->GetWidget()->GetClientAreaBoundsInScreen().OffsetFromOrigin()); } } @@ -653,8 +653,7 @@ void View::ConvertPointToScreen(const View* src, gfx::Point* p) { const Widget* widget = src->GetWidget(); if (widget) { ConvertPointToWidget(src, p); - gfx::Rect r = widget->GetClientAreaBoundsInScreen(); - p->SetPoint(p->x() + r.x(), p->y() + r.y()); + *p = p->Add(widget->GetClientAreaBoundsInScreen().OffsetFromOrigin()); } } @@ -666,15 +665,14 @@ void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) { const views::Widget* widget = dst->GetWidget(); if (!widget) return; - const gfx::Rect r = widget->GetClientAreaBoundsInScreen(); - p->Offset(-r.x(), -r.y()); + *p = p->Add(-widget->GetClientAreaBoundsInScreen().OffsetFromOrigin()); views::View::ConvertPointFromWidget(dst, p); } gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { gfx::Rect x_rect = rect; GetTransform().TransformRect(&x_rect); - x_rect.Offset(GetMirroredPosition()); + x_rect.Offset(GetMirroredPosition().OffsetFromOrigin()); return x_rect; } @@ -725,7 +723,7 @@ void View::Paint(gfx::Canvas* canvas) { // Non-empty clip, translate the graphics such that 0,0 corresponds to // where this view is located (related to its parent). - canvas->Translate(GetMirroredPosition()); + canvas->Translate(GetMirroredPosition().OffsetFromOrigin()); canvas->Transform(GetTransform()); PaintCommon(canvas); @@ -1041,9 +1039,9 @@ void View::OnDragDone() { } // static -bool View::ExceededDragThreshold(int delta_x, int delta_y) { - return (abs(delta_x) > GetHorizontalDragThreshold() || - abs(delta_y) > GetVerticalDragThreshold()); +bool View::ExceededDragThreshold(const gfx::Vector2d& delta) { + return (abs(delta.x()) > GetHorizontalDragThreshold() || + abs(delta.y()) > GetVerticalDragThreshold()); } // Scrolling ------------------------------------------------------------------- @@ -1527,7 +1525,7 @@ void View::PaintCommon(gfx::Canvas* canvas) { // request the canvas to be flipped. ScopedCanvas scoped(canvas); if (FlipCanvasOnPaintForRTLUI()) { - canvas->Translate(gfx::Point(width(), 0)); + canvas->Translate(gfx::Vector2d(width(), 0)); canvas->Scale(-1, 1); } @@ -1939,9 +1937,8 @@ bool View::ProcessMouseDragged(const ui::MouseEvent& event, // done. ContextMenuController* context_menu_controller = context_menu_controller_; const bool possible_drag = drag_info->possible_drag; - if (possible_drag && ExceededDragThreshold( - drag_info->start_pt.x() - event.x(), - drag_info->start_pt.y() - event.y())) { + if (possible_drag && + ExceededDragThreshold(drag_info->start_pt - event.location())) { if (!drag_controller_ || drag_controller_->CanStartDragForView( this, drag_info->start_pt, event.location())) diff --git a/ui/views/view.h b/ui/views/view.h index 65b2247..3f05eeb 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -23,6 +23,7 @@ #include "ui/compositor/layer_owner.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" +#include "ui/gfx/vector2d.h" #include "ui/views/background.h" #include "ui/views/border.h" #include "ui/views/focus_border.h" @@ -859,7 +860,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Returns true if the mouse was dragged enough to start a drag operation. // delta_x and y are the distance the mouse was dragged. - static bool ExceededDragThreshold(int delta_x, int delta_y); + static bool ExceededDragThreshold(const gfx::Vector2d& delta); // Accessibility ------------------------------------------------------------- diff --git a/ui/views/widget/desktop_native_widget_aura.cc b/ui/views/widget/desktop_native_widget_aura.cc index 8dd2a44..73ef5de 100644 --- a/ui/views/widget/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_native_widget_aura.cc @@ -400,7 +400,7 @@ void DesktopNativeWidgetAura::SetInactiveRenderingDisabled(bool value) { } Widget::MoveLoopResult DesktopNativeWidgetAura::RunMoveLoop( - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { return desktop_root_window_host_->RunMoveLoop(drag_offset); } diff --git a/ui/views/widget/desktop_native_widget_aura.h b/ui/views/widget/desktop_native_widget_aura.h index 3f2f247..608cd86 100644 --- a/ui/views/widget/desktop_native_widget_aura.h +++ b/ui/views/widget/desktop_native_widget_aura.h @@ -120,7 +120,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; diff --git a/ui/views/widget/desktop_root_window_host.h b/ui/views/widget/desktop_root_window_host.h index eedd3d9..0f175d3 100644 --- a/ui/views/widget/desktop_root_window_host.h +++ b/ui/views/widget/desktop_root_window_host.h @@ -82,7 +82,8 @@ class VIEWS_EXPORT DesktopRootWindowHost { virtual void ClearNativeFocus() = 0; - virtual Widget::MoveLoopResult RunMoveLoop(const gfx::Point& drag_offset) = 0; + virtual Widget::MoveLoopResult RunMoveLoop( + const gfx::Vector2d& drag_offset) = 0; virtual void EndMoveLoop() = 0; virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; diff --git a/ui/views/widget/desktop_root_window_host_linux.cc b/ui/views/widget/desktop_root_window_host_linux.cc index 6dadcd0..b05fcf3 100644 --- a/ui/views/widget/desktop_root_window_host_linux.cc +++ b/ui/views/widget/desktop_root_window_host_linux.cc @@ -525,7 +525,7 @@ void DesktopRootWindowHostLinux::ClearNativeFocus() { } Widget::MoveLoopResult DesktopRootWindowHostLinux::RunMoveLoop( - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { SetCapture(); if (x11_window_move_client_->RunMoveLoop(content_window_, drag_offset) == diff --git a/ui/views/widget/desktop_root_window_host_linux.h b/ui/views/widget/desktop_root_window_host_linux.h index b8f6fe9..e24c5b9 100644 --- a/ui/views/widget/desktop_root_window_host_linux.h +++ b/ui/views/widget/desktop_root_window_host_linux.h @@ -124,7 +124,7 @@ class VIEWS_EXPORT DesktopRootWindowHostLinux virtual void SetWindowTitle(const string16& title) OVERRIDE; virtual void ClearNativeFocus() OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual bool ShouldUseNativeFrame() OVERRIDE; diff --git a/ui/views/widget/desktop_root_window_host_win.cc b/ui/views/widget/desktop_root_window_host_win.cc index ec60ef3..c5b14f9 100644 --- a/ui/views/widget/desktop_root_window_host_win.cc +++ b/ui/views/widget/desktop_root_window_host_win.cc @@ -264,7 +264,7 @@ void DesktopRootWindowHostWin::ClearNativeFocus() { } Widget::MoveLoopResult DesktopRootWindowHostWin::RunMoveLoop( - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { return message_handler_->RunMoveLoop(drag_offset) ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; } diff --git a/ui/views/widget/desktop_root_window_host_win.h b/ui/views/widget/desktop_root_window_host_win.h index 7aafddb..5880600 100644 --- a/ui/views/widget/desktop_root_window_host_win.h +++ b/ui/views/widget/desktop_root_window_host_win.h @@ -78,7 +78,7 @@ class VIEWS_EXPORT DesktopRootWindowHostWin virtual void SetWindowTitle(const string16& title) OVERRIDE; virtual void ClearNativeFocus() OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual bool ShouldUseNativeFrame() OVERRIDE; diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index a37ebd2..85fafe1 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -592,7 +592,7 @@ void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { } Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { if (window_->parent() && aura::client::GetWindowMoveClient(window_->parent())) { SetCapture(); diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index 1011f61..8f6157f 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -121,7 +121,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; diff --git a/ui/views/widget/native_widget_private.h b/ui/views/widget/native_widget_private.h index 30f3848..c210a20 100644 --- a/ui/views/widget/native_widget_private.h +++ b/ui/views/widget/native_widget_private.h @@ -210,7 +210,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget { virtual void ClearNativeFocus() = 0; virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0; virtual void SetInactiveRenderingDisabled(bool value) = 0; - virtual Widget::MoveLoopResult RunMoveLoop(const gfx::Point& drag_offset) = 0; + virtual Widget::MoveLoopResult RunMoveLoop( + const gfx::Vector2d& drag_offset) = 0; virtual void EndMoveLoop() = 0; virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index 904e8c1..628b0cc 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -471,7 +471,7 @@ void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { } Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop( - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { return message_handler_->RunMoveLoop(drag_offset) ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; } diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index 530e4cd..b50e925 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -164,7 +164,7 @@ class VIEWS_EXPORT NativeWidgetWin : public internal::NativeWidgetPrivate, virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index fef8cd2..8a42f91 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -483,7 +483,7 @@ void Widget::SetVisibilityChangedAnimationsEnabled(bool value) { native_widget_->SetVisibilityChangedAnimationsEnabled(value); } -Widget::MoveLoopResult Widget::RunMoveLoop(const gfx::Point& drag_offset) { +Widget::MoveLoopResult Widget::RunMoveLoop(const gfx::Vector2d& drag_offset) { return native_widget_->RunMoveLoop(drag_offset); } diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h index 48f1295..224d7b6 100644 --- a/ui/views/widget/widget.h +++ b/ui/views/widget/widget.h @@ -331,7 +331,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // the move completes. |drag_offset| is the offset from the top left corner // of the window to the point where the cursor is dragging, and is used to // offset the bounds of the window from the cursor. - MoveLoopResult RunMoveLoop(const gfx::Point& drag_offset); + MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset); // Stops a previously started move loop. This is not immediate. void EndMoveLoop(); diff --git a/ui/views/widget/x11_desktop_window_move_client.cc b/ui/views/widget/x11_desktop_window_move_client.cc index adb6ff3..e17db87 100644 --- a/ui/views/widget/x11_desktop_window_move_client.cc +++ b/ui/views/widget/x11_desktop_window_move_client.cc @@ -71,7 +71,7 @@ ui::EventResult X11DesktopWindowMoveClient::PreHandleGestureEvent( aura::client::WindowMoveResult X11DesktopWindowMoveClient::RunMoveLoop( aura::Window* source, - const gfx::Point& drag_offset) { + const gfx::Vector2d& drag_offset) { DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. in_move_loop_ = true; window_offset_ = drag_offset; diff --git a/ui/views/widget/x11_desktop_window_move_client.h b/ui/views/widget/x11_desktop_window_move_client.h index f80bce6..9cb3a7c 100644 --- a/ui/views/widget/x11_desktop_window_move_client.h +++ b/ui/views/widget/x11_desktop_window_move_client.h @@ -36,7 +36,7 @@ class VIEWS_EXPORT X11DesktopWindowMoveClient // Overridden from aura::client::WindowMoveClient: virtual aura::client::WindowMoveResult RunMoveLoop( aura::Window* window, - const gfx::Point& drag_offset) OVERRIDE; + const gfx::Vector2d& drag_offset) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; private: @@ -46,7 +46,7 @@ class VIEWS_EXPORT X11DesktopWindowMoveClient // Our cursor offset from the top left window origin when the drag // started. Used to calculate the window's new bounds relative to the current // location of the cursor. - gfx::Point window_offset_; + gfx::Vector2d window_offset_; base::Closure quit_closure_; }; diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc index 0312549..70ed1bf 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc @@ -668,7 +668,7 @@ bool HWNDMessageHandler::IsMaximized() const { return !!::IsZoomed(hwnd()); } -bool HWNDMessageHandler::RunMoveLoop(const gfx::Point& drag_offset) { +bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset) { ReleaseCapture(); MoveLoopMouseWatcher watcher(this); SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, GetMessagePos()); diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h index 9a96340..96b9931 100644 --- a/ui/views/win/hwnd_message_handler.h +++ b/ui/views/win/hwnd_message_handler.h @@ -104,7 +104,7 @@ class VIEWS_EXPORT HWNDMessageHandler : public ui::WindowImpl, bool IsMinimized() const; bool IsMaximized() const; - bool RunMoveLoop(const gfx::Point& drag_offset); + bool RunMoveLoop(const gfx::Vector2d& drag_offset); void EndMoveLoop(); // Tells the HWND its client area has changed. diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index c0c6c78..57e157f 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1167,9 +1167,10 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint( return false; gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); + gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); // Convert |paint_bounds| to be relative to the left-top corner of the plugin. gfx::Rect relative_paint_bounds(paint_bounds); - relative_paint_bounds.Offset(-plugin_origin.x(), -plugin_origin.y()); + relative_paint_bounds.Offset(-plugin_offset); gfx::Rect pixel_plugin_backing_store_rect( 0, 0, image_data->width(), image_data->height()); @@ -1192,9 +1193,9 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint( } *dib = image_data->PlatformImage()->GetTransportDIB(); - plugin_backing_store_rect.Offset(plugin_origin); + plugin_backing_store_rect.Offset(plugin_offset); *location = plugin_backing_store_rect; - clip_page.Offset(plugin_origin); + clip_page.Offset(plugin_offset); *clip = clip_page; // The plugin scale factor is inverted, e.g. for a device scale factor of 2x // the plugin scale factor is 0.5. diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc index aaad035..c7013d2 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc @@ -705,8 +705,7 @@ void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, int dx, int dy, gfx::Rect* invalidated_rect) { - gfx::ScrollCanvas(image_data_->GetCanvas(), - clip, gfx::Point(dx, dy)); + gfx::ScrollCanvas(image_data_->GetCanvas(), clip, gfx::Vector2d(dx, dy)); *invalidated_rect = clip; } |