| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 6 | 6 |
| 7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 | 11 |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
| 19 #include "ui/accessibility/ax_enums.h" | 19 #include "ui/accessibility/ax_enums.h" |
| 20 #include "ui/base/cursor/cursor.h" | 20 #include "ui/base/cursor/cursor.h" |
| 21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
| 22 #include "ui/base/ui_base_switches_util.h" | |
| 23 #include "ui/compositor/compositor.h" | 22 #include "ui/compositor/compositor.h" |
| 24 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
| 25 #include "ui/compositor/layer_animator.h" | 24 #include "ui/compositor/layer_animator.h" |
| 26 #include "ui/events/event_target_iterator.h" | 25 #include "ui/events/event_target_iterator.h" |
| 27 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/interpolated_transform.h" | 27 #include "ui/gfx/interpolated_transform.h" |
| 29 #include "ui/gfx/path.h" | 28 #include "ui/gfx/path.h" |
| 30 #include "ui/gfx/point3_f.h" | 29 #include "ui/gfx/point3_f.h" |
| 31 #include "ui/gfx/point_conversions.h" | 30 #include "ui/gfx/point_conversions.h" |
| 32 #include "ui/gfx/rect_conversions.h" | 31 #include "ui/gfx/rect_conversions.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 root = root->parent(); | 80 root = root->parent(); |
| 82 return root; | 81 return root; |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace | 84 } // namespace |
| 86 | 85 |
| 87 namespace views { | 86 namespace views { |
| 88 | 87 |
| 89 namespace internal { | 88 namespace internal { |
| 90 | 89 |
| 91 // This event handler receives events in the post-target phase and takes care of | |
| 92 // the following: | |
| 93 // - Generates context menu, or initiates drag-and-drop, from gesture events. | |
| 94 class PostEventDispatchHandler : public ui::EventHandler { | |
| 95 public: | |
| 96 explicit PostEventDispatchHandler(View* owner) | |
| 97 : owner_(owner), | |
| 98 touch_dnd_enabled_(switches::IsTouchDragDropEnabled()) { | |
| 99 } | |
| 100 virtual ~PostEventDispatchHandler() {} | |
| 101 | |
| 102 private: | |
| 103 // Overridden from ui::EventHandler: | |
| 104 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | |
| 105 DCHECK_EQ(ui::EP_POSTTARGET, event->phase()); | |
| 106 if (event->handled()) | |
| 107 return; | |
| 108 | |
| 109 if (touch_dnd_enabled_) { | |
| 110 if (event->type() == ui::ET_GESTURE_LONG_PRESS && | |
| 111 (!owner_->drag_controller() || | |
| 112 owner_->drag_controller()->CanStartDragForView( | |
| 113 owner_, event->location(), event->location()))) { | |
| 114 if (owner_->DoDrag(*event, event->location(), | |
| 115 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) { | |
| 116 event->StopPropagation(); | |
| 117 return; | |
| 118 } | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 if (owner_->context_menu_controller() && | |
| 123 (event->type() == ui::ET_GESTURE_LONG_PRESS || | |
| 124 event->type() == ui::ET_GESTURE_LONG_TAP || | |
| 125 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { | |
| 126 gfx::Point location(event->location()); | |
| 127 View::ConvertPointToScreen(owner_, &location); | |
| 128 owner_->ShowContextMenu(location, ui::MENU_SOURCE_TOUCH); | |
| 129 event->StopPropagation(); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 View* owner_; | |
| 134 bool touch_dnd_enabled_; | |
| 135 | |
| 136 DISALLOW_COPY_AND_ASSIGN(PostEventDispatchHandler); | |
| 137 }; | |
| 138 | |
| 139 } // namespace internal | 90 } // namespace internal |
| 140 | 91 |
| 141 // static | 92 // static |
| 142 ViewsDelegate* ViewsDelegate::views_delegate = NULL; | 93 ViewsDelegate* ViewsDelegate::views_delegate = NULL; |
| 143 | 94 |
| 144 // static | 95 // static |
| 145 const char View::kViewClassName[] = "View"; | 96 const char View::kViewClassName[] = "View"; |
| 146 | 97 |
| 147 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
| 148 // View, public: | 99 // View, public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 164 flip_canvas_on_paint_for_rtl_ui_(false), | 115 flip_canvas_on_paint_for_rtl_ui_(false), |
| 165 paint_to_layer_(false), | 116 paint_to_layer_(false), |
| 166 accelerator_focus_manager_(NULL), | 117 accelerator_focus_manager_(NULL), |
| 167 registered_accelerator_count_(0), | 118 registered_accelerator_count_(0), |
| 168 next_focusable_view_(NULL), | 119 next_focusable_view_(NULL), |
| 169 previous_focusable_view_(NULL), | 120 previous_focusable_view_(NULL), |
| 170 focusable_(false), | 121 focusable_(false), |
| 171 accessibility_focusable_(false), | 122 accessibility_focusable_(false), |
| 172 context_menu_controller_(NULL), | 123 context_menu_controller_(NULL), |
| 173 drag_controller_(NULL), | 124 drag_controller_(NULL), |
| 174 post_dispatch_handler_(new internal::PostEventDispatchHandler(this)), | |
| 175 native_view_accessibility_(NULL) { | 125 native_view_accessibility_(NULL) { |
| 176 AddPostTargetHandler(post_dispatch_handler_.get()); | |
| 177 } | 126 } |
| 178 | 127 |
| 179 View::~View() { | 128 View::~View() { |
| 180 if (parent_) | 129 if (parent_) |
| 181 parent_->RemoveChildView(this); | 130 parent_->RemoveChildView(this); |
| 182 | 131 |
| 183 ViewStorage::GetInstance()->ViewRemoved(this); | 132 ViewStorage::GetInstance()->ViewRemoved(this); |
| 184 | 133 |
| 185 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 134 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
| 186 (*i)->parent_ = NULL; | 135 (*i)->parent_ = NULL; |
| (...skipping 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2535 // Message the RootView to do the drag and drop. That way if we're removed | 2484 // Message the RootView to do the drag and drop. That way if we're removed |
| 2536 // the RootView can detect it and avoid calling us back. | 2485 // the RootView can detect it and avoid calling us back. |
| 2537 gfx::Point widget_location(event.location()); | 2486 gfx::Point widget_location(event.location()); |
| 2538 ConvertPointToWidget(this, &widget_location); | 2487 ConvertPointToWidget(this, &widget_location); |
| 2539 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2488 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2540 // WARNING: we may have been deleted. | 2489 // WARNING: we may have been deleted. |
| 2541 return true; | 2490 return true; |
| 2542 } | 2491 } |
| 2543 | 2492 |
| 2544 } // namespace views | 2493 } // namespace views |
| OLD | NEW |