| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/touchui/touch_selection_controller_impl.h" | 5 #include "ui/views/touchui/touch_selection_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 gfx::Image* GetRightHandleImage() { | 109 gfx::Image* GetRightHandleImage() { |
| 110 static gfx::Image* handle_image = nullptr; | 110 static gfx::Image* handle_image = nullptr; |
| 111 if (!handle_image) { | 111 if (!handle_image) { |
| 112 handle_image = &ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 112 handle_image = &ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 113 IDR_TEXT_SELECTION_HANDLE_RIGHT); | 113 IDR_TEXT_SELECTION_HANDLE_RIGHT); |
| 114 } | 114 } |
| 115 return handle_image; | 115 return handle_image; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Return the appropriate handle image based on the bound's type | 118 // Return the appropriate handle image based on the bound's type |
| 119 gfx::Image* GetHandleImage(ui::SelectionBound::Type bound_type) { | 119 gfx::Image* GetHandleImage(gfx::SelectionBound::Type bound_type) { |
| 120 switch(bound_type) { | 120 switch(bound_type) { |
| 121 case ui::SelectionBound::LEFT: | 121 case gfx::SelectionBound::LEFT: |
| 122 return GetLeftHandleImage(); | 122 return GetLeftHandleImage(); |
| 123 case ui::SelectionBound::CENTER: | 123 case gfx::SelectionBound::CENTER: |
| 124 return GetCenterHandleImage(); | 124 return GetCenterHandleImage(); |
| 125 case ui::SelectionBound::RIGHT: | 125 case gfx::SelectionBound::RIGHT: |
| 126 return GetRightHandleImage(); | 126 return GetRightHandleImage(); |
| 127 default: | 127 default: |
| 128 NOTREACHED() << "Invalid touch handle bound type: " << bound_type; | 128 NOTREACHED() << "Invalid touch handle bound type: " << bound_type; |
| 129 return nullptr; | 129 return nullptr; |
| 130 }; | 130 }; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Calculates the bounds of the widget containing the selection handle based | 133 // Calculates the bounds of the widget containing the selection handle based |
| 134 // on the SelectionBound's type and location | 134 // on the SelectionBound's type and location |
| 135 gfx::Rect GetSelectionWidgetBounds(const ui::SelectionBound& bound) { | 135 gfx::Rect GetSelectionWidgetBounds(const gfx::SelectionBound& bound) { |
| 136 gfx::Size image_size = GetHandleImage(bound.type())->Size(); | 136 gfx::Size image_size = GetHandleImage(bound.type())->Size(); |
| 137 int widget_width = image_size.width() + 2 * kSelectionHandleHorizPadding; | 137 int widget_width = image_size.width() + 2 * kSelectionHandleHorizPadding; |
| 138 int widget_height = bound.GetHeight() + image_size.height() + | 138 int widget_height = bound.GetHeight() + image_size.height() + |
| 139 kSelectionHandleVerticalVisualOffset + | 139 kSelectionHandleVerticalVisualOffset + |
| 140 kSelectionHandleVertPadding; | 140 kSelectionHandleVertPadding; |
| 141 // Due to the shape of the handle images, the widget is aligned differently to | 141 // Due to the shape of the handle images, the widget is aligned differently to |
| 142 // the selection bound depending on the type of the bound. | 142 // the selection bound depending on the type of the bound. |
| 143 int widget_left = 0; | 143 int widget_left = 0; |
| 144 switch (bound.type()) { | 144 switch (bound.type()) { |
| 145 case ui::SelectionBound::LEFT: | 145 case gfx::SelectionBound::LEFT: |
| 146 widget_left = bound.edge_top_rounded().x() - image_size.width() - | 146 widget_left = bound.edge_top_rounded().x() - image_size.width() - |
| 147 kSelectionHandleHorizPadding; | 147 kSelectionHandleHorizPadding; |
| 148 break; | 148 break; |
| 149 case ui::SelectionBound::RIGHT: | 149 case gfx::SelectionBound::RIGHT: |
| 150 widget_left = bound.edge_top_rounded().x() - kSelectionHandleHorizPadding; | 150 widget_left = bound.edge_top_rounded().x() - kSelectionHandleHorizPadding; |
| 151 break; | 151 break; |
| 152 case ui::SelectionBound::CENTER: | 152 case gfx::SelectionBound::CENTER: |
| 153 widget_left = bound.edge_top_rounded().x() - widget_width / 2; | 153 widget_left = bound.edge_top_rounded().x() - widget_width / 2; |
| 154 break; | 154 break; |
| 155 default: | 155 default: |
| 156 NOTREACHED() << "Undefined bound type."; | 156 NOTREACHED() << "Undefined bound type."; |
| 157 break; | 157 break; |
| 158 }; | 158 }; |
| 159 return gfx::Rect( | 159 return gfx::Rect( |
| 160 widget_left, bound.edge_top_rounded().y(), widget_width, widget_height); | 160 widget_left, bound.edge_top_rounded().y(), widget_width, widget_height); |
| 161 } | 161 } |
| 162 | 162 |
| 163 gfx::Size GetMaxHandleImageSize() { | 163 gfx::Size GetMaxHandleImageSize() { |
| 164 gfx::Rect center_rect = gfx::Rect(GetCenterHandleImage()->Size()); | 164 gfx::Rect center_rect = gfx::Rect(GetCenterHandleImage()->Size()); |
| 165 gfx::Rect left_rect = gfx::Rect(GetLeftHandleImage()->Size()); | 165 gfx::Rect left_rect = gfx::Rect(GetLeftHandleImage()->Size()); |
| 166 gfx::Rect right_rect = gfx::Rect(GetRightHandleImage()->Size()); | 166 gfx::Rect right_rect = gfx::Rect(GetRightHandleImage()->Size()); |
| 167 gfx::Rect union_rect = center_rect; | 167 gfx::Rect union_rect = center_rect; |
| 168 union_rect.Union(left_rect); | 168 union_rect.Union(left_rect); |
| 169 union_rect.Union(right_rect); | 169 union_rect.Union(right_rect); |
| 170 return union_rect.size(); | 170 return union_rect.size(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Convenience methods to convert a |bound| from screen to the |client|'s | 173 // Convenience methods to convert a |bound| from screen to the |client|'s |
| 174 // coordinate system and vice versa. | 174 // coordinate system and vice versa. |
| 175 // Note that this is not quite correct because it does not take into account | 175 // Note that this is not quite correct because it does not take into account |
| 176 // transforms such as rotation and scaling. This should be in TouchEditable. | 176 // transforms such as rotation and scaling. This should be in TouchEditable. |
| 177 // TODO(varunjain): Fix this. | 177 // TODO(varunjain): Fix this. |
| 178 ui::SelectionBound ConvertFromScreen(ui::TouchEditable* client, | 178 gfx::SelectionBound ConvertFromScreen(ui::TouchEditable* client, |
| 179 const ui::SelectionBound& bound) { | 179 const gfx::SelectionBound& bound) { |
| 180 ui::SelectionBound result = bound; | 180 gfx::SelectionBound result = bound; |
| 181 gfx::Point edge_bottom = bound.edge_bottom_rounded(); | 181 gfx::Point edge_bottom = bound.edge_bottom_rounded(); |
| 182 gfx::Point edge_top = bound.edge_top_rounded(); | 182 gfx::Point edge_top = bound.edge_top_rounded(); |
| 183 client->ConvertPointFromScreen(&edge_bottom); | 183 client->ConvertPointFromScreen(&edge_bottom); |
| 184 client->ConvertPointFromScreen(&edge_top); | 184 client->ConvertPointFromScreen(&edge_top); |
| 185 result.SetEdge(gfx::PointF(edge_top), gfx::PointF(edge_bottom)); | 185 result.SetEdge(gfx::PointF(edge_top), gfx::PointF(edge_bottom)); |
| 186 return result; | 186 return result; |
| 187 } | 187 } |
| 188 | 188 |
| 189 ui::SelectionBound ConvertToScreen(ui::TouchEditable* client, | 189 gfx::SelectionBound ConvertToScreen(ui::TouchEditable* client, |
| 190 const ui::SelectionBound& bound) { | 190 const gfx::SelectionBound& bound) { |
| 191 ui::SelectionBound result = bound; | 191 gfx::SelectionBound result = bound; |
| 192 gfx::Point edge_bottom = bound.edge_bottom_rounded(); | 192 gfx::Point edge_bottom = bound.edge_bottom_rounded(); |
| 193 gfx::Point edge_top = bound.edge_top_rounded(); | 193 gfx::Point edge_top = bound.edge_top_rounded(); |
| 194 client->ConvertPointToScreen(&edge_bottom); | 194 client->ConvertPointToScreen(&edge_bottom); |
| 195 client->ConvertPointToScreen(&edge_top); | 195 client->ConvertPointToScreen(&edge_top); |
| 196 result.SetEdge(gfx::PointF(edge_top), gfx::PointF(edge_bottom)); | 196 result.SetEdge(gfx::PointF(edge_top), gfx::PointF(edge_bottom)); |
| 197 return result; | 197 return result; |
| 198 } | 198 } |
| 199 | 199 |
| 200 gfx::Rect BoundToRect(const ui::SelectionBound& bound) { | 200 gfx::Rect BoundToRect(const gfx::SelectionBound& bound) { |
| 201 return gfx::BoundingRect(bound.edge_top_rounded(), | 201 return gfx::BoundingRect(bound.edge_top_rounded(), |
| 202 bound.edge_bottom_rounded()); | 202 bound.edge_bottom_rounded()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace | 205 } // namespace |
| 206 | 206 |
| 207 namespace views { | 207 namespace views { |
| 208 | 208 |
| 209 typedef TouchSelectionControllerImpl::EditingHandleView EditingHandleView; | 209 typedef TouchSelectionControllerImpl::EditingHandleView EditingHandleView; |
| 210 | 210 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 aura::Window* window = widget_->GetNativeWindow(); | 242 aura::Window* window = widget_->GetNativeWindow(); |
| 243 window->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 243 window->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
| 244 new TouchHandleWindowTargeter(window, this))); | 244 new TouchHandleWindowTargeter(window, this))); |
| 245 | 245 |
| 246 // We are owned by the TouchSelectionControllerImpl. | 246 // We are owned by the TouchSelectionControllerImpl. |
| 247 set_owned_by_client(); | 247 set_owned_by_client(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 ~EditingHandleView() override { SetWidgetVisible(false, false); } | 250 ~EditingHandleView() override { SetWidgetVisible(false, false); } |
| 251 | 251 |
| 252 ui::SelectionBound::Type selection_bound_type() { | 252 gfx::SelectionBound::Type selection_bound_type() { |
| 253 return selection_bound_.type(); | 253 return selection_bound_.type(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Overridden from views::WidgetDelegateView: | 256 // Overridden from views::WidgetDelegateView: |
| 257 bool WidgetHasHitTestMask() const override { return true; } | 257 bool WidgetHasHitTestMask() const override { return true; } |
| 258 | 258 |
| 259 void GetWidgetHitTestMask(gfx::Path* mask) const override { | 259 void GetWidgetHitTestMask(gfx::Path* mask) const override { |
| 260 gfx::Size image_size = image_->Size(); | 260 gfx::Size image_size = image_->Size(); |
| 261 mask->addRect( | 261 mask->addRect( |
| 262 SkIntToScalar(0), | 262 SkIntToScalar(0), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 if (visible) | 337 if (visible) |
| 338 widget_->Show(); | 338 widget_->Show(); |
| 339 else | 339 else |
| 340 widget_->Hide(); | 340 widget_->Hide(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 // If |is_visible| is true, this will update the widget and trigger a repaint | 343 // If |is_visible| is true, this will update the widget and trigger a repaint |
| 344 // if necessary. Otherwise this will only update the internal state: | 344 // if necessary. Otherwise this will only update the internal state: |
| 345 // |selection_bound_| and |image_|, so that the state is valid for the time | 345 // |selection_bound_| and |image_|, so that the state is valid for the time |
| 346 // this becomes visible. | 346 // this becomes visible. |
| 347 void SetBoundInScreen(const ui::SelectionBound& bound, bool is_visible) { | 347 void SetBoundInScreen(const gfx::SelectionBound& bound, bool is_visible) { |
| 348 bool update_bound_type = false; | 348 bool update_bound_type = false; |
| 349 // Cursor handle should always have the bound type CENTER | 349 // Cursor handle should always have the bound type CENTER |
| 350 DCHECK(!is_cursor_handle_ || bound.type() == ui::SelectionBound::CENTER); | 350 DCHECK(!is_cursor_handle_ || bound.type() == gfx::SelectionBound::CENTER); |
| 351 | 351 |
| 352 if (bound.type() != selection_bound_.type()) { | 352 if (bound.type() != selection_bound_.type()) { |
| 353 // Unless this is a cursor handle, do not set the type to CENTER - | 353 // Unless this is a cursor handle, do not set the type to CENTER - |
| 354 // selection handles corresponding to a selection should always use left | 354 // selection handles corresponding to a selection should always use left |
| 355 // or right handle image. If selection handles are dragged to be located | 355 // or right handle image. If selection handles are dragged to be located |
| 356 // at the same spot, the |bound|'s type here will be CENTER for both of | 356 // at the same spot, the |bound|'s type here will be CENTER for both of |
| 357 // them. In this case do not update the type of the |selection_bound_|. | 357 // them. In this case do not update the type of the |selection_bound_|. |
| 358 if (bound.type() != ui::SelectionBound::CENTER || is_cursor_handle_) | 358 if (bound.type() != gfx::SelectionBound::CENTER || is_cursor_handle_) |
| 359 update_bound_type = true; | 359 update_bound_type = true; |
| 360 } | 360 } |
| 361 if (update_bound_type) { | 361 if (update_bound_type) { |
| 362 selection_bound_.set_type(bound.type()); | 362 selection_bound_.set_type(bound.type()); |
| 363 image_ = GetHandleImage(bound.type()); | 363 image_ = GetHandleImage(bound.type()); |
| 364 if (is_visible) | 364 if (is_visible) |
| 365 SchedulePaint(); | 365 SchedulePaint(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 if (!is_visible) | 368 if (!is_visible) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 385 return; | 385 return; |
| 386 draw_invisible_ = draw_invisible; | 386 draw_invisible_ = draw_invisible; |
| 387 SchedulePaint(); | 387 SchedulePaint(); |
| 388 } | 388 } |
| 389 | 389 |
| 390 private: | 390 private: |
| 391 std::unique_ptr<Widget> widget_; | 391 std::unique_ptr<Widget> widget_; |
| 392 TouchSelectionControllerImpl* controller_; | 392 TouchSelectionControllerImpl* controller_; |
| 393 | 393 |
| 394 // In local coordinates | 394 // In local coordinates |
| 395 ui::SelectionBound selection_bound_; | 395 gfx::SelectionBound selection_bound_; |
| 396 gfx::Image* image_; | 396 gfx::Image* image_; |
| 397 | 397 |
| 398 // If true, this is a handle corresponding to the single cursor, otherwise it | 398 // If true, this is a handle corresponding to the single cursor, otherwise it |
| 399 // is a handle corresponding to one of the two selection bounds. | 399 // is a handle corresponding to one of the two selection bounds. |
| 400 bool is_cursor_handle_; | 400 bool is_cursor_handle_; |
| 401 | 401 |
| 402 // Offset applied to the scroll events location when calling | 402 // Offset applied to the scroll events location when calling |
| 403 // TouchSelectionControllerImpl::SelectionHandleDragged while dragging the | 403 // TouchSelectionControllerImpl::SelectionHandleDragged while dragging the |
| 404 // handle. | 404 // handle. |
| 405 gfx::Vector2d drag_offset_; | 405 gfx::Vector2d drag_offset_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 UMA_HISTOGRAM_BOOLEAN("Event.TouchSelection.EndedWithAction", | 456 UMA_HISTOGRAM_BOOLEAN("Event.TouchSelection.EndedWithAction", |
| 457 command_executed_); | 457 command_executed_); |
| 458 HideQuickMenu(); | 458 HideQuickMenu(); |
| 459 aura::Env::GetInstance()->RemovePreTargetHandler(this); | 459 aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| 460 if (client_widget_) | 460 if (client_widget_) |
| 461 client_widget_->RemoveObserver(this); | 461 client_widget_->RemoveObserver(this); |
| 462 client_view_->GetNativeView()->RemoveObserver(this); | 462 client_view_->GetNativeView()->RemoveObserver(this); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void TouchSelectionControllerImpl::SelectionChanged() { | 465 void TouchSelectionControllerImpl::SelectionChanged() { |
| 466 ui::SelectionBound anchor, focus; | 466 gfx::SelectionBound anchor, focus; |
| 467 client_view_->GetSelectionEndPoints(&anchor, &focus); | 467 client_view_->GetSelectionEndPoints(&anchor, &focus); |
| 468 ui::SelectionBound screen_bound_anchor = | 468 gfx::SelectionBound screen_bound_anchor = |
| 469 ConvertToScreen(client_view_, anchor); | 469 ConvertToScreen(client_view_, anchor); |
| 470 ui::SelectionBound screen_bound_focus = ConvertToScreen(client_view_, focus); | 470 gfx::SelectionBound screen_bound_focus = ConvertToScreen(client_view_, focus); |
| 471 gfx::Rect client_bounds = client_view_->GetBounds(); | 471 gfx::Rect client_bounds = client_view_->GetBounds(); |
| 472 if (anchor.edge_top().y() < client_bounds.y()) { | 472 if (anchor.edge_top().y() < client_bounds.y()) { |
| 473 auto anchor_edge_top = gfx::PointF(anchor.edge_top_rounded()); | 473 auto anchor_edge_top = gfx::PointF(anchor.edge_top_rounded()); |
| 474 anchor_edge_top.set_y(client_bounds.y()); | 474 anchor_edge_top.set_y(client_bounds.y()); |
| 475 anchor.SetEdgeTop(anchor_edge_top); | 475 anchor.SetEdgeTop(anchor_edge_top); |
| 476 } | 476 } |
| 477 if (focus.edge_top().y() < client_bounds.y()) { | 477 if (focus.edge_top().y() < client_bounds.y()) { |
| 478 auto focus_edge_top = gfx::PointF(focus.edge_top_rounded()); | 478 auto focus_edge_top = gfx::PointF(focus.edge_top_rounded()); |
| 479 focus_edge_top.set_y(client_bounds.y()); | 479 focus_edge_top.set_y(client_bounds.y()); |
| 480 focus.SetEdgeTop(focus_edge_top); | 480 focus.SetEdgeTop(focus_edge_top); |
| 481 } | 481 } |
| 482 ui::SelectionBound screen_bound_anchor_clipped = | 482 gfx::SelectionBound screen_bound_anchor_clipped = |
| 483 ConvertToScreen(client_view_, anchor); | 483 ConvertToScreen(client_view_, anchor); |
| 484 ui::SelectionBound screen_bound_focus_clipped = | 484 gfx::SelectionBound screen_bound_focus_clipped = |
| 485 ConvertToScreen(client_view_, focus); | 485 ConvertToScreen(client_view_, focus); |
| 486 if (screen_bound_anchor_clipped == selection_bound_1_clipped_ && | 486 if (screen_bound_anchor_clipped == selection_bound_1_clipped_ && |
| 487 screen_bound_focus_clipped == selection_bound_2_clipped_) | 487 screen_bound_focus_clipped == selection_bound_2_clipped_) |
| 488 return; | 488 return; |
| 489 | 489 |
| 490 selection_bound_1_ = screen_bound_anchor; | 490 selection_bound_1_ = screen_bound_anchor; |
| 491 selection_bound_2_ = screen_bound_focus; | 491 selection_bound_2_ = screen_bound_focus; |
| 492 selection_bound_1_clipped_ = screen_bound_anchor_clipped; | 492 selection_bound_1_clipped_ = screen_bound_anchor_clipped; |
| 493 selection_bound_2_clipped_ = screen_bound_focus_clipped; | 493 selection_bound_2_clipped_ = screen_bound_focus_clipped; |
| 494 | 494 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 DCHECK(dragging_handle_); | 572 DCHECK(dragging_handle_); |
| 573 gfx::Point drag_pos_in_client = drag_pos; | 573 gfx::Point drag_pos_in_client = drag_pos; |
| 574 ConvertPointToClientView(dragging_handle_, &drag_pos_in_client); | 574 ConvertPointToClientView(dragging_handle_, &drag_pos_in_client); |
| 575 | 575 |
| 576 if (dragging_handle_ == cursor_handle_.get()) { | 576 if (dragging_handle_ == cursor_handle_.get()) { |
| 577 client_view_->MoveCaretTo(drag_pos_in_client); | 577 client_view_->MoveCaretTo(drag_pos_in_client); |
| 578 return; | 578 return; |
| 579 } | 579 } |
| 580 | 580 |
| 581 // Find the stationary selection handle. | 581 // Find the stationary selection handle. |
| 582 ui::SelectionBound anchor_bound = | 582 gfx::SelectionBound anchor_bound = |
| 583 selection_handle_1_.get() == dragging_handle_ ? selection_bound_2_ | 583 selection_handle_1_.get() == dragging_handle_ ? selection_bound_2_ |
| 584 : selection_bound_1_; | 584 : selection_bound_1_; |
| 585 | 585 |
| 586 // Find selection end points in client_view's coordinate system. | 586 // Find selection end points in client_view's coordinate system. |
| 587 gfx::Point p2 = anchor_bound.edge_top_rounded(); | 587 gfx::Point p2 = anchor_bound.edge_top_rounded(); |
| 588 p2.Offset(0, anchor_bound.GetHeight() / 2); | 588 p2.Offset(0, anchor_bound.GetHeight() / 2); |
| 589 client_view_->ConvertPointFromScreen(&p2); | 589 client_view_->ConvertPointFromScreen(&p2); |
| 590 | 590 |
| 591 // Instruct client_view to select the region between p1 and p2. The position | 591 // Instruct client_view to select the region between p1 and p2. The position |
| 592 // of |fixed_handle| is the start and that of |dragging_handle| is the end | 592 // of |fixed_handle| is the start and that of |dragging_handle| is the end |
| 593 // of selection. | 593 // of selection. |
| 594 client_view_->SelectRect(p2, drag_pos_in_client); | 594 client_view_->SelectRect(p2, drag_pos_in_client); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void TouchSelectionControllerImpl::ConvertPointToClientView( | 597 void TouchSelectionControllerImpl::ConvertPointToClientView( |
| 598 EditingHandleView* source, gfx::Point* point) { | 598 EditingHandleView* source, gfx::Point* point) { |
| 599 View::ConvertPointToScreen(source, point); | 599 View::ConvertPointToScreen(source, point); |
| 600 client_view_->ConvertPointFromScreen(point); | 600 client_view_->ConvertPointFromScreen(point); |
| 601 } | 601 } |
| 602 | 602 |
| 603 void TouchSelectionControllerImpl::SetHandleBound( | 603 void TouchSelectionControllerImpl::SetHandleBound( |
| 604 EditingHandleView* handle, | 604 EditingHandleView* handle, |
| 605 const ui::SelectionBound& bound, | 605 const gfx::SelectionBound& bound, |
| 606 const ui::SelectionBound& bound_in_screen) { | 606 const gfx::SelectionBound& bound_in_screen) { |
| 607 handle->SetWidgetVisible(ShouldShowHandleFor(bound), false); | 607 handle->SetWidgetVisible(ShouldShowHandleFor(bound), false); |
| 608 handle->SetBoundInScreen(bound_in_screen, handle->IsWidgetVisible()); | 608 handle->SetBoundInScreen(bound_in_screen, handle->IsWidgetVisible()); |
| 609 } | 609 } |
| 610 | 610 |
| 611 bool TouchSelectionControllerImpl::ShouldShowHandleFor( | 611 bool TouchSelectionControllerImpl::ShouldShowHandleFor( |
| 612 const ui::SelectionBound& bound) const { | 612 const gfx::SelectionBound& bound) const { |
| 613 if (bound.GetHeight() < kSelectionHandleBarMinHeight) | 613 if (bound.GetHeight() < kSelectionHandleBarMinHeight) |
| 614 return false; | 614 return false; |
| 615 gfx::Rect client_bounds = client_view_->GetBounds(); | 615 gfx::Rect client_bounds = client_view_->GetBounds(); |
| 616 client_bounds.Inset(0, 0, 0, -kSelectionHandleBarBottomAllowance); | 616 client_bounds.Inset(0, 0, 0, -kSelectionHandleBarBottomAllowance); |
| 617 return client_bounds.Contains(BoundToRect(bound)); | 617 return client_bounds.Contains(BoundToRect(bound)); |
| 618 } | 618 } |
| 619 | 619 |
| 620 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { | 620 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { |
| 621 return client_view_->IsCommandIdEnabled(command_id); | 621 return client_view_->IsCommandIdEnabled(command_id); |
| 622 } | 622 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 712 } |
| 713 | 713 |
| 714 void TouchSelectionControllerImpl::HideQuickMenu() { | 714 void TouchSelectionControllerImpl::HideQuickMenu() { |
| 715 if (ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()) | 715 if (ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()) |
| 716 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); | 716 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); |
| 717 quick_menu_timer_.Stop(); | 717 quick_menu_timer_.Stop(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 gfx::Rect TouchSelectionControllerImpl::GetQuickMenuAnchorRect() const { | 720 gfx::Rect TouchSelectionControllerImpl::GetQuickMenuAnchorRect() const { |
| 721 // Get selection end points in client_view's space. | 721 // Get selection end points in client_view's space. |
| 722 ui::SelectionBound b1_in_screen = selection_bound_1_clipped_; | 722 gfx::SelectionBound b1_in_screen = selection_bound_1_clipped_; |
| 723 ui::SelectionBound b2_in_screen = cursor_handle_->IsWidgetVisible() | 723 gfx::SelectionBound b2_in_screen = cursor_handle_->IsWidgetVisible() |
| 724 ? b1_in_screen | 724 ? b1_in_screen |
| 725 : selection_bound_2_clipped_; | 725 : selection_bound_2_clipped_; |
| 726 // Convert from screen to client. | 726 // Convert from screen to client. |
| 727 ui::SelectionBound b1 = ConvertFromScreen(client_view_, b1_in_screen); | 727 gfx::SelectionBound b1 = ConvertFromScreen(client_view_, b1_in_screen); |
| 728 ui::SelectionBound b2 = ConvertFromScreen(client_view_, b2_in_screen); | 728 gfx::SelectionBound b2 = ConvertFromScreen(client_view_, b2_in_screen); |
| 729 | 729 |
| 730 // if selection is completely inside the view, we display the quick menu in | 730 // if selection is completely inside the view, we display the quick menu in |
| 731 // the middle of the end points on the top. Else, we show it above the visible | 731 // the middle of the end points on the top. Else, we show it above the visible |
| 732 // handle. If no handle is visible, we do not show the menu. | 732 // handle. If no handle is visible, we do not show the menu. |
| 733 gfx::Rect menu_anchor; | 733 gfx::Rect menu_anchor; |
| 734 if (ShouldShowHandleFor(b1) && ShouldShowHandleFor(b2)) | 734 if (ShouldShowHandleFor(b1) && ShouldShowHandleFor(b2)) |
| 735 menu_anchor = ui::RectBetweenSelectionBounds(b1_in_screen, b2_in_screen); | 735 menu_anchor = gfx::RectBetweenSelectionBounds(b1_in_screen, b2_in_screen); |
| 736 else if (ShouldShowHandleFor(b1)) | 736 else if (ShouldShowHandleFor(b1)) |
| 737 menu_anchor = BoundToRect(b1_in_screen); | 737 menu_anchor = BoundToRect(b1_in_screen); |
| 738 else if (ShouldShowHandleFor(b2)) | 738 else if (ShouldShowHandleFor(b2)) |
| 739 menu_anchor = BoundToRect(b2_in_screen); | 739 menu_anchor = BoundToRect(b2_in_screen); |
| 740 else | 740 else |
| 741 return menu_anchor; | 741 return menu_anchor; |
| 742 | 742 |
| 743 // Enlarge the anchor rect so that the menu is offset from the text at least | 743 // Enlarge the anchor rect so that the menu is offset from the text at least |
| 744 // by the same distance the handles are offset from the text. | 744 // by the same distance the handles are offset from the text. |
| 745 menu_anchor.Inset(0, -kSelectionHandleVerticalVisualOffset); | 745 menu_anchor.Inset(0, -kSelectionHandleVerticalVisualOffset); |
| 746 | 746 |
| 747 return menu_anchor; | 747 return menu_anchor; |
| 748 } | 748 } |
| 749 | 749 |
| 750 gfx::NativeView TouchSelectionControllerImpl::GetCursorHandleNativeView() { | 750 gfx::NativeView TouchSelectionControllerImpl::GetCursorHandleNativeView() { |
| 751 return cursor_handle_->GetWidget()->GetNativeView(); | 751 return cursor_handle_->GetWidget()->GetNativeView(); |
| 752 } | 752 } |
| 753 | 753 |
| 754 ui::SelectionBound::Type | 754 gfx::SelectionBound::Type |
| 755 TouchSelectionControllerImpl::GetSelectionHandle1Type() { | 755 TouchSelectionControllerImpl::GetSelectionHandle1Type() { |
| 756 return selection_handle_1_->selection_bound_type(); | 756 return selection_handle_1_->selection_bound_type(); |
| 757 } | 757 } |
| 758 | 758 |
| 759 gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle1Bounds() { | 759 gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle1Bounds() { |
| 760 return selection_handle_1_->GetBoundsInScreen(); | 760 return selection_handle_1_->GetBoundsInScreen(); |
| 761 } | 761 } |
| 762 | 762 |
| 763 gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle2Bounds() { | 763 gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle2Bounds() { |
| 764 return selection_handle_2_->GetBoundsInScreen(); | 764 return selection_handle_2_->GetBoundsInScreen(); |
| 765 } | 765 } |
| 766 | 766 |
| 767 gfx::Rect TouchSelectionControllerImpl::GetCursorHandleBounds() { | 767 gfx::Rect TouchSelectionControllerImpl::GetCursorHandleBounds() { |
| 768 return cursor_handle_->GetBoundsInScreen(); | 768 return cursor_handle_->GetBoundsInScreen(); |
| 769 } | 769 } |
| 770 | 770 |
| 771 bool TouchSelectionControllerImpl::IsSelectionHandle1Visible() { | 771 bool TouchSelectionControllerImpl::IsSelectionHandle1Visible() { |
| 772 return selection_handle_1_->IsWidgetVisible(); | 772 return selection_handle_1_->IsWidgetVisible(); |
| 773 } | 773 } |
| 774 | 774 |
| 775 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 775 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
| 776 return selection_handle_2_->IsWidgetVisible(); | 776 return selection_handle_2_->IsWidgetVisible(); |
| 777 } | 777 } |
| 778 | 778 |
| 779 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { | 779 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { |
| 780 return cursor_handle_->IsWidgetVisible(); | 780 return cursor_handle_->IsWidgetVisible(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 gfx::Rect TouchSelectionControllerImpl::GetExpectedHandleBounds( | 783 gfx::Rect TouchSelectionControllerImpl::GetExpectedHandleBounds( |
| 784 const ui::SelectionBound& bound) { | 784 const gfx::SelectionBound& bound) { |
| 785 return GetSelectionWidgetBounds(bound); | 785 return GetSelectionWidgetBounds(bound); |
| 786 } | 786 } |
| 787 | 787 |
| 788 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { | 788 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { |
| 789 return selection_handle_1_.get(); | 789 return selection_handle_1_.get(); |
| 790 } | 790 } |
| 791 | 791 |
| 792 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { | 792 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { |
| 793 return selection_handle_2_.get(); | 793 return selection_handle_2_.get(); |
| 794 } | 794 } |
| 795 | 795 |
| 796 } // namespace views | 796 } // namespace views |
| OLD | NEW |