| 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/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 class TouchHandleWindowTargeter : public wm::MaskedWindowTargeter { | 131 class TouchHandleWindowTargeter : public wm::MaskedWindowTargeter { |
| 132 public: | 132 public: |
| 133 TouchHandleWindowTargeter(aura::Window* window, | 133 TouchHandleWindowTargeter(aura::Window* window, |
| 134 EditingHandleView* handle_view); | 134 EditingHandleView* handle_view); |
| 135 | 135 |
| 136 virtual ~TouchHandleWindowTargeter() {} | 136 virtual ~TouchHandleWindowTargeter() {} |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 // wm::MaskedWindowTargeter: | 139 // wm::MaskedWindowTargeter: |
| 140 virtual bool GetHitTestMask(aura::Window* window, | 140 virtual bool GetHitTestMask(aura::Window* window, |
| 141 gfx::Path* mask) const OVERRIDE; | 141 gfx::Path* mask) const override; |
| 142 | 142 |
| 143 EditingHandleView* handle_view_; | 143 EditingHandleView* handle_view_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(TouchHandleWindowTargeter); | 145 DISALLOW_COPY_AND_ASSIGN(TouchHandleWindowTargeter); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // A View that displays the text selection handle. | 148 // A View that displays the text selection handle. |
| 149 class TouchSelectionControllerImpl::EditingHandleView | 149 class TouchSelectionControllerImpl::EditingHandleView |
| 150 : public views::WidgetDelegateView { | 150 : public views::WidgetDelegateView { |
| 151 public: | 151 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 | 163 |
| 164 // We are owned by the TouchSelectionController. | 164 // We are owned by the TouchSelectionController. |
| 165 set_owned_by_client(); | 165 set_owned_by_client(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 virtual ~EditingHandleView() { | 168 virtual ~EditingHandleView() { |
| 169 SetWidgetVisible(false, false); | 169 SetWidgetVisible(false, false); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Overridden from views::WidgetDelegateView: | 172 // Overridden from views::WidgetDelegateView: |
| 173 virtual bool WidgetHasHitTestMask() const OVERRIDE { | 173 virtual bool WidgetHasHitTestMask() const override { |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE { | 177 virtual void GetWidgetHitTestMask(gfx::Path* mask) const override { |
| 178 gfx::Size image_size = GetHandleImageSize(); | 178 gfx::Size image_size = GetHandleImageSize(); |
| 179 mask->addRect(SkIntToScalar(0), SkIntToScalar(selection_rect_.height()), | 179 mask->addRect(SkIntToScalar(0), SkIntToScalar(selection_rect_.height()), |
| 180 SkIntToScalar(image_size.width()) + 2 * kSelectionHandleHorizPadding, | 180 SkIntToScalar(image_size.width()) + 2 * kSelectionHandleHorizPadding, |
| 181 SkIntToScalar(selection_rect_.height() + image_size.height() + | 181 SkIntToScalar(selection_rect_.height() + image_size.height() + |
| 182 kSelectionHandleVertPadding)); | 182 kSelectionHandleVertPadding)); |
| 183 } | 183 } |
| 184 | 184 |
| 185 virtual void DeleteDelegate() OVERRIDE { | 185 virtual void DeleteDelegate() override { |
| 186 // We are owned and deleted by TouchSelectionController. | 186 // We are owned and deleted by TouchSelectionController. |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Overridden from views::View: | 189 // Overridden from views::View: |
| 190 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 190 virtual void OnPaint(gfx::Canvas* canvas) override { |
| 191 if (draw_invisible_) | 191 if (draw_invisible_) |
| 192 return; | 192 return; |
| 193 gfx::Size image_size = GetHandleImageSize(); | 193 gfx::Size image_size = GetHandleImageSize(); |
| 194 int cursor_pos_x = image_size.width() / 2 - kSelectionHandleLineWidth + | 194 int cursor_pos_x = image_size.width() / 2 - kSelectionHandleLineWidth + |
| 195 kSelectionHandleHorizPadding; | 195 kSelectionHandleHorizPadding; |
| 196 | 196 |
| 197 // Draw the cursor line. | 197 // Draw the cursor line. |
| 198 canvas->FillRect( | 198 canvas->FillRect( |
| 199 gfx::Rect(cursor_pos_x, 0, | 199 gfx::Rect(cursor_pos_x, 0, |
| 200 2 * kSelectionHandleLineWidth + 1, selection_rect_.height()), | 200 2 * kSelectionHandleLineWidth + 1, selection_rect_.height()), |
| 201 kSelectionHandleLineColor); | 201 kSelectionHandleLineColor); |
| 202 | 202 |
| 203 // Draw the handle image. | 203 // Draw the handle image. |
| 204 canvas->DrawImageInt(*GetHandleImage()->ToImageSkia(), | 204 canvas->DrawImageInt(*GetHandleImage()->ToImageSkia(), |
| 205 kSelectionHandleHorizPadding, selection_rect_.height()); | 205 kSelectionHandleHorizPadding, selection_rect_.height()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 208 virtual void OnGestureEvent(ui::GestureEvent* event) override { |
| 209 event->SetHandled(); | 209 event->SetHandled(); |
| 210 switch (event->type()) { | 210 switch (event->type()) { |
| 211 case ui::ET_GESTURE_SCROLL_BEGIN: | 211 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 212 widget_->SetCapture(this); | 212 widget_->SetCapture(this); |
| 213 controller_->SetDraggingHandle(this); | 213 controller_->SetDraggingHandle(this); |
| 214 drag_offset_ = event->y() - selection_rect_.height() + | 214 drag_offset_ = event->y() - selection_rect_.height() + |
| 215 kSelectionHandleVerticalDragOffset; | 215 kSelectionHandleVerticalDragOffset; |
| 216 break; | 216 break; |
| 217 case ui::ET_GESTURE_SCROLL_UPDATE: { | 217 case ui::ET_GESTURE_SCROLL_UPDATE: { |
| 218 gfx::Point drag_pos(event->location().x(), | 218 gfx::Point drag_pos(event->location().x(), |
| 219 event->location().y() - drag_offset_); | 219 event->location().y() - drag_offset_); |
| 220 controller_->SelectionHandleDragged(drag_pos); | 220 controller_->SelectionHandleDragged(drag_pos); |
| 221 break; | 221 break; |
| 222 } | 222 } |
| 223 case ui::ET_GESTURE_SCROLL_END: | 223 case ui::ET_GESTURE_SCROLL_END: |
| 224 case ui::ET_SCROLL_FLING_START: | 224 case ui::ET_SCROLL_FLING_START: |
| 225 widget_->ReleaseCapture(); | 225 widget_->ReleaseCapture(); |
| 226 controller_->SetDraggingHandle(NULL); | 226 controller_->SetDraggingHandle(NULL); |
| 227 break; | 227 break; |
| 228 default: | 228 default: |
| 229 break; | 229 break; |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 233 virtual gfx::Size GetPreferredSize() const override { |
| 234 gfx::Size image_size = GetHandleImageSize(); | 234 gfx::Size image_size = GetHandleImageSize(); |
| 235 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, | 235 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, |
| 236 image_size.height() + selection_rect_.height() + | 236 image_size.height() + selection_rect_.height() + |
| 237 kSelectionHandleVertPadding); | 237 kSelectionHandleVertPadding); |
| 238 } | 238 } |
| 239 | 239 |
| 240 bool IsWidgetVisible() const { | 240 bool IsWidgetVisible() const { |
| 241 return widget_->IsVisible(); | 241 return widget_->IsVisible(); |
| 242 } | 242 } |
| 243 | 243 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 625 |
| 626 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 626 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
| 627 return selection_handle_2_->IsWidgetVisible(); | 627 return selection_handle_2_->IsWidgetVisible(); |
| 628 } | 628 } |
| 629 | 629 |
| 630 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { | 630 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { |
| 631 return cursor_handle_->IsWidgetVisible(); | 631 return cursor_handle_->IsWidgetVisible(); |
| 632 } | 632 } |
| 633 | 633 |
| 634 } // namespace views | 634 } // namespace views |
| OLD | NEW |