| 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> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 const views::View* root = view; | 86 const views::View* root = view; |
| 87 while (root && root->parent()) | 87 while (root && root->parent()) |
| 88 root = root->parent(); | 88 root = root->parent(); |
| 89 return root; | 89 return root; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 namespace views { | 94 namespace views { |
| 95 | 95 |
| 96 namespace internal { |
| 97 |
| 98 // This event handler receives events in the post-target phase and takes care of |
| 99 // the following: |
| 100 // - Generates context menu, or initiates drag-and-drop, from gesture events. |
| 101 class PostEventDispatchHandler : public ui::EventHandler { |
| 102 public: |
| 103 explicit PostEventDispatchHandler(View* owner) |
| 104 : owner_(owner), |
| 105 touch_dnd_enabled_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 106 switches::kEnableTouchDragDrop)) { |
| 107 } |
| 108 virtual ~PostEventDispatchHandler() {} |
| 109 |
| 110 private: |
| 111 // Overridden from ui::EventHandler: |
| 112 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 113 DCHECK_EQ(ui::EP_POSTTARGET, event->phase()); |
| 114 if (event->handled()) |
| 115 return; |
| 116 |
| 117 if (touch_dnd_enabled_) { |
| 118 if (event->type() == ui::ET_GESTURE_LONG_PRESS && |
| 119 (!owner_->drag_controller() || |
| 120 owner_->drag_controller()->CanStartDragForView( |
| 121 owner_, event->location(), event->location()))) { |
| 122 if (owner_->DoDrag(*event, event->location(), |
| 123 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) { |
| 124 event->StopPropagation(); |
| 125 return; |
| 126 } |
| 127 } |
| 128 } |
| 129 |
| 130 if (owner_->context_menu_controller() && |
| 131 (event->type() == ui::ET_GESTURE_LONG_PRESS || |
| 132 event->type() == ui::ET_GESTURE_LONG_TAP || |
| 133 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { |
| 134 gfx::Point location(event->location()); |
| 135 View::ConvertPointToScreen(owner_, &location); |
| 136 owner_->ShowContextMenu(location, true); |
| 137 event->StopPropagation(); |
| 138 } |
| 139 } |
| 140 |
| 141 View* owner_; |
| 142 bool touch_dnd_enabled_; |
| 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(PostEventDispatchHandler); |
| 145 }; |
| 146 |
| 147 } // namespace internal |
| 148 |
| 96 // static | 149 // static |
| 97 ViewsDelegate* ViewsDelegate::views_delegate = NULL; | 150 ViewsDelegate* ViewsDelegate::views_delegate = NULL; |
| 98 | 151 |
| 99 // static | 152 // static |
| 100 const char View::kViewClassName[] = "views/View"; | 153 const char View::kViewClassName[] = "views/View"; |
| 101 | 154 |
| 102 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
| 103 // View, public: | 156 // View, public: |
| 104 | 157 |
| 105 // Creation and lifetime ------------------------------------------------------- | 158 // Creation and lifetime ------------------------------------------------------- |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 flip_canvas_on_paint_for_rtl_ui_(false), | 172 flip_canvas_on_paint_for_rtl_ui_(false), |
| 120 paint_to_layer_(false), | 173 paint_to_layer_(false), |
| 121 accelerator_registration_delayed_(false), | 174 accelerator_registration_delayed_(false), |
| 122 accelerator_focus_manager_(NULL), | 175 accelerator_focus_manager_(NULL), |
| 123 registered_accelerator_count_(0), | 176 registered_accelerator_count_(0), |
| 124 next_focusable_view_(NULL), | 177 next_focusable_view_(NULL), |
| 125 previous_focusable_view_(NULL), | 178 previous_focusable_view_(NULL), |
| 126 focusable_(false), | 179 focusable_(false), |
| 127 accessibility_focusable_(false), | 180 accessibility_focusable_(false), |
| 128 context_menu_controller_(NULL), | 181 context_menu_controller_(NULL), |
| 129 drag_controller_(NULL) { | 182 drag_controller_(NULL), |
| 183 ALLOW_THIS_IN_INITIALIZER_LIST(post_dispatch_handler_( |
| 184 new internal::PostEventDispatchHandler(this))) { |
| 185 AddPostTargetHandler(post_dispatch_handler_.get()); |
| 130 } | 186 } |
| 131 | 187 |
| 132 View::~View() { | 188 View::~View() { |
| 133 if (parent_) | 189 if (parent_) |
| 134 parent_->RemoveChildView(this); | 190 parent_->RemoveChildView(this); |
| 135 | 191 |
| 136 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 192 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
| 137 (*i)->parent_ = NULL; | 193 (*i)->parent_ = NULL; |
| 138 if (!(*i)->owned_by_client_) | 194 if (!(*i)->owned_by_client_) |
| 139 delete *i; | 195 delete *i; |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 917 |
| 862 bool View::OnKeyReleased(const ui::KeyEvent& event) { | 918 bool View::OnKeyReleased(const ui::KeyEvent& event) { |
| 863 return false; | 919 return false; |
| 864 } | 920 } |
| 865 | 921 |
| 866 bool View::OnMouseWheel(const ui::MouseWheelEvent& event) { | 922 bool View::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 867 return false; | 923 return false; |
| 868 } | 924 } |
| 869 | 925 |
| 870 void View::OnKeyEvent(ui::KeyEvent* event) { | 926 void View::OnKeyEvent(ui::KeyEvent* event) { |
| 927 bool consumed = (event->type() == ui::ET_KEY_PRESSED) ? OnKeyPressed(*event) : |
| 928 OnKeyReleased(*event); |
| 929 if (consumed) |
| 930 event->StopPropagation(); |
| 871 } | 931 } |
| 872 | 932 |
| 873 void View::OnMouseEvent(ui::MouseEvent* event) { | 933 void View::OnMouseEvent(ui::MouseEvent* event) { |
| 874 } | 934 } |
| 875 | 935 |
| 876 void View::OnScrollEvent(ui::ScrollEvent* event) { | 936 void View::OnScrollEvent(ui::ScrollEvent* event) { |
| 877 } | 937 } |
| 878 | 938 |
| 879 void View::OnTouchEvent(ui::TouchEvent* event) { | 939 void View::OnTouchEvent(ui::TouchEvent* event) { |
| 880 } | 940 } |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 if (HitTestPoint(location)) { | 2043 if (HitTestPoint(location)) { |
| 1984 ConvertPointToScreen(this, &location); | 2044 ConvertPointToScreen(this, &location); |
| 1985 ShowContextMenu(location, true); | 2045 ShowContextMenu(location, true); |
| 1986 } | 2046 } |
| 1987 } else { | 2047 } else { |
| 1988 OnMouseReleased(event); | 2048 OnMouseReleased(event); |
| 1989 } | 2049 } |
| 1990 // WARNING: we may have been deleted. | 2050 // WARNING: we may have been deleted. |
| 1991 } | 2051 } |
| 1992 | 2052 |
| 1993 void View::ProcessTouchEvent(ui::TouchEvent* event) { | |
| 1994 OnTouchEvent(event); | |
| 1995 } | |
| 1996 | |
| 1997 void View::ProcessGestureEvent(ui::GestureEvent* event) { | |
| 1998 OnGestureEvent(event); | |
| 1999 if (event->handled()) | |
| 2000 return; | |
| 2001 | |
| 2002 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 2003 switches::kEnableTouchDragDrop)) { | |
| 2004 if (event->type() == ui::ET_GESTURE_LONG_PRESS && | |
| 2005 (!drag_controller_ || drag_controller_->CanStartDragForView( | |
| 2006 this, event->location(), event->location()))) { | |
| 2007 if (DoDrag(*event, event->location(), | |
| 2008 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) { | |
| 2009 event->StopPropagation(); | |
| 2010 return; | |
| 2011 } | |
| 2012 } | |
| 2013 } | |
| 2014 | |
| 2015 if (context_menu_controller_ && | |
| 2016 (event->type() == ui::ET_GESTURE_LONG_PRESS || | |
| 2017 event->type() == ui::ET_GESTURE_LONG_TAP || | |
| 2018 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { | |
| 2019 gfx::Point location(event->location()); | |
| 2020 ConvertPointToScreen(this, &location); | |
| 2021 ShowContextMenu(location, true); | |
| 2022 event->StopPropagation(); | |
| 2023 } | |
| 2024 } | |
| 2025 | |
| 2026 // Accelerators ---------------------------------------------------------------- | 2053 // Accelerators ---------------------------------------------------------------- |
| 2027 | 2054 |
| 2028 void View::RegisterPendingAccelerators() { | 2055 void View::RegisterPendingAccelerators() { |
| 2029 if (!accelerators_.get() || | 2056 if (!accelerators_.get() || |
| 2030 registered_accelerator_count_ == accelerators_->size()) { | 2057 registered_accelerator_count_ == accelerators_->size()) { |
| 2031 // No accelerators are waiting for registration. | 2058 // No accelerators are waiting for registration. |
| 2032 return; | 2059 return; |
| 2033 } | 2060 } |
| 2034 | 2061 |
| 2035 if (!GetWidget()) { | 2062 if (!GetWidget()) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 ConvertPointToWidget(this, &widget_location); | 2189 ConvertPointToWidget(this, &widget_location); |
| 2163 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2190 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
| 2164 source); | 2191 source); |
| 2165 return true; | 2192 return true; |
| 2166 #else | 2193 #else |
| 2167 return false; | 2194 return false; |
| 2168 #endif // !defined(OS_MACOSX) | 2195 #endif // !defined(OS_MACOSX) |
| 2169 } | 2196 } |
| 2170 | 2197 |
| 2171 } // namespace views | 2198 } // namespace views |
| OLD | NEW |