| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Overridden from ui::EventHandler: | 103 // Overridden from ui::EventHandler: |
| 104 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 104 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 105 DCHECK_EQ(ui::EP_POSTTARGET, event->phase()); | 105 DCHECK_EQ(ui::EP_POSTTARGET, event->phase()); |
| 106 if (event->handled()) | 106 if (event->handled()) |
| 107 return; | 107 return; |
| 108 | 108 |
| 109 if (touch_dnd_enabled_) { | 109 if (touch_dnd_enabled_) { |
| 110 if (event->type() == ui::ET_GESTURE_LONG_PRESS && | 110 if (event->type() == ui::ET_GESTURE_LONG_PRESS && |
| 111 (!owner_->drag_controller() || | 111 (!owner_->drag_controller() || |
| 112 owner_->drag_controller()->CanStartDragForView( | 112 owner_->drag_controller()->CanStartDragForView( |
| 113 owner_, event->location(), event->location()))) { | 113 owner_, |
| 114 if (owner_->DoDrag(*event, event->location(), | 114 gfx::ToFlooredPoint(event->location()), |
| 115 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) { | 115 gfx::ToFlooredPoint(event->location())))) { |
| 116 if (owner_->DoDrag(*event, |
| 117 gfx::ToFlooredPoint(event->location()), |
| 118 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) { |
| 116 event->StopPropagation(); | 119 event->StopPropagation(); |
| 117 return; | 120 return; |
| 118 } | 121 } |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 | 124 |
| 122 if (owner_->context_menu_controller() && | 125 if (owner_->context_menu_controller() && |
| 123 (event->type() == ui::ET_GESTURE_LONG_PRESS || | 126 (event->type() == ui::ET_GESTURE_LONG_PRESS || |
| 124 event->type() == ui::ET_GESTURE_LONG_TAP || | 127 event->type() == ui::ET_GESTURE_LONG_TAP || |
| 125 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { | 128 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { |
| 126 gfx::Point location(event->location()); | 129 gfx::Point location(gfx::ToFlooredPoint(event->location())); |
| 127 View::ConvertPointToScreen(owner_, &location); | 130 View::ConvertPointToScreen(owner_, &location); |
| 128 owner_->ShowContextMenu(location, ui::MENU_SOURCE_TOUCH); | 131 owner_->ShowContextMenu(location, ui::MENU_SOURCE_TOUCH); |
| 129 event->StopPropagation(); | 132 event->StopPropagation(); |
| 130 } | 133 } |
| 131 } | 134 } |
| 132 | 135 |
| 133 View* owner_; | 136 View* owner_; |
| 134 bool touch_dnd_enabled_; | 137 bool touch_dnd_enabled_; |
| 135 | 138 |
| 136 DISALLOW_COPY_AND_ASSIGN(PostEventDispatchHandler); | 139 DISALLOW_COPY_AND_ASSIGN(PostEventDispatchHandler); |
| (...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 Widget* widget = GetWidget(); | 2162 Widget* widget = GetWidget(); |
| 2160 if (widget) | 2163 if (widget) |
| 2161 widget->UpdateRootLayers(); | 2164 widget->UpdateRootLayers(); |
| 2162 } | 2165 } |
| 2163 | 2166 |
| 2164 // Input ----------------------------------------------------------------------- | 2167 // Input ----------------------------------------------------------------------- |
| 2165 | 2168 |
| 2166 bool View::ProcessMousePressed(const ui::MouseEvent& event) { | 2169 bool View::ProcessMousePressed(const ui::MouseEvent& event) { |
| 2167 int drag_operations = | 2170 int drag_operations = |
| 2168 (enabled_ && event.IsOnlyLeftMouseButton() && | 2171 (enabled_ && event.IsOnlyLeftMouseButton() && |
| 2169 HitTestPoint(event.location())) ? | 2172 HitTestPoint(gfx::ToFlooredPoint(event.location()))) |
| 2170 GetDragOperations(event.location()) : 0; | 2173 ? GetDragOperations(gfx::ToFlooredPoint(event.location())) |
| 2174 : 0; |
| 2171 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 2175 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
| 2172 context_menu_controller_ : 0; | 2176 context_menu_controller_ : 0; |
| 2173 View::DragInfo* drag_info = GetDragInfo(); | 2177 View::DragInfo* drag_info = GetDragInfo(); |
| 2174 | 2178 |
| 2175 // TODO(sky): for debugging 360238. | 2179 // TODO(sky): for debugging 360238. |
| 2176 int storage_id = 0; | 2180 int storage_id = 0; |
| 2177 if (event.IsOnlyRightMouseButton() && context_menu_controller && | 2181 if (event.IsOnlyRightMouseButton() && context_menu_controller && |
| 2178 kContextMenuOnMousePress && HitTestPoint(event.location())) { | 2182 kContextMenuOnMousePress && |
| 2183 HitTestPoint(gfx::ToFlooredPoint(event.location()))) { |
| 2179 ViewStorage* view_storage = ViewStorage::GetInstance(); | 2184 ViewStorage* view_storage = ViewStorage::GetInstance(); |
| 2180 storage_id = view_storage->CreateStorageID(); | 2185 storage_id = view_storage->CreateStorageID(); |
| 2181 view_storage->StoreView(storage_id, this); | 2186 view_storage->StoreView(storage_id, this); |
| 2182 } | 2187 } |
| 2183 | 2188 |
| 2184 const bool enabled = enabled_; | 2189 const bool enabled = enabled_; |
| 2185 const bool result = OnMousePressed(event); | 2190 const bool result = OnMousePressed(event); |
| 2186 | 2191 |
| 2187 if (!enabled) | 2192 if (!enabled) |
| 2188 return result; | 2193 return result; |
| 2189 | 2194 |
| 2190 if (event.IsOnlyRightMouseButton() && context_menu_controller && | 2195 if (event.IsOnlyRightMouseButton() && context_menu_controller && |
| 2191 kContextMenuOnMousePress) { | 2196 kContextMenuOnMousePress) { |
| 2192 // Assume that if there is a context menu controller we won't be deleted | 2197 // Assume that if there is a context menu controller we won't be deleted |
| 2193 // from mouse pressed. | 2198 // from mouse pressed. |
| 2194 gfx::Point location(event.location()); | 2199 gfx::Point location(gfx::ToFlooredPoint(event.location())); |
| 2195 if (HitTestPoint(location)) { | 2200 if (HitTestPoint(location)) { |
| 2196 if (storage_id != 0) | 2201 if (storage_id != 0) |
| 2197 CHECK_EQ(this, ViewStorage::GetInstance()->RetrieveView(storage_id)); | 2202 CHECK_EQ(this, ViewStorage::GetInstance()->RetrieveView(storage_id)); |
| 2198 ConvertPointToScreen(this, &location); | 2203 ConvertPointToScreen(this, &location); |
| 2199 ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); | 2204 ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); |
| 2200 return true; | 2205 return true; |
| 2201 } | 2206 } |
| 2202 } | 2207 } |
| 2203 | 2208 |
| 2204 // WARNING: we may have been deleted, don't use any View variables. | 2209 // WARNING: we may have been deleted, don't use any View variables. |
| 2205 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 2210 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
| 2206 drag_info->PossibleDrag(event.location()); | 2211 drag_info->PossibleDrag(gfx::ToFlooredPoint(event.location())); |
| 2207 return true; | 2212 return true; |
| 2208 } | 2213 } |
| 2209 return !!context_menu_controller || result; | 2214 return !!context_menu_controller || result; |
| 2210 } | 2215 } |
| 2211 | 2216 |
| 2212 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { | 2217 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { |
| 2213 // Copy the field, that way if we're deleted after drag and drop no harm is | 2218 // Copy the field, that way if we're deleted after drag and drop no harm is |
| 2214 // done. | 2219 // done. |
| 2215 ContextMenuController* context_menu_controller = context_menu_controller_; | 2220 ContextMenuController* context_menu_controller = context_menu_controller_; |
| 2216 const bool possible_drag = GetDragInfo()->possible_drag; | 2221 const bool possible_drag = GetDragInfo()->possible_drag; |
| 2217 if (possible_drag && | 2222 if (possible_drag && |
| 2218 ExceededDragThreshold(GetDragInfo()->start_pt - event.location()) && | 2223 ExceededDragThreshold(GetDragInfo()->start_pt - |
| 2224 gfx::ToFlooredPoint(event.location())) && |
| 2219 (!drag_controller_ || | 2225 (!drag_controller_ || |
| 2220 drag_controller_->CanStartDragForView( | 2226 drag_controller_->CanStartDragForView( |
| 2221 this, GetDragInfo()->start_pt, event.location()))) { | 2227 this, |
| 2228 GetDragInfo()->start_pt, |
| 2229 gfx::ToFlooredPoint(event.location())))) { |
| 2222 DoDrag(event, GetDragInfo()->start_pt, | 2230 DoDrag(event, GetDragInfo()->start_pt, |
| 2223 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 2231 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
| 2224 } else { | 2232 } else { |
| 2225 if (OnMouseDragged(event)) | 2233 if (OnMouseDragged(event)) |
| 2226 return true; | 2234 return true; |
| 2227 // Fall through to return value based on context menu controller. | 2235 // Fall through to return value based on context menu controller. |
| 2228 } | 2236 } |
| 2229 // WARNING: we may have been deleted. | 2237 // WARNING: we may have been deleted. |
| 2230 return (context_menu_controller != NULL) || possible_drag; | 2238 return (context_menu_controller != NULL) || possible_drag; |
| 2231 } | 2239 } |
| 2232 | 2240 |
| 2233 void View::ProcessMouseReleased(const ui::MouseEvent& event) { | 2241 void View::ProcessMouseReleased(const ui::MouseEvent& event) { |
| 2234 if (!kContextMenuOnMousePress && context_menu_controller_ && | 2242 if (!kContextMenuOnMousePress && context_menu_controller_ && |
| 2235 event.IsOnlyRightMouseButton()) { | 2243 event.IsOnlyRightMouseButton()) { |
| 2236 // Assume that if there is a context menu controller we won't be deleted | 2244 // Assume that if there is a context menu controller we won't be deleted |
| 2237 // from mouse released. | 2245 // from mouse released. |
| 2238 gfx::Point location(event.location()); | 2246 gfx::Point location(gfx::ToFlooredPoint(event.location())); |
| 2239 OnMouseReleased(event); | 2247 OnMouseReleased(event); |
| 2240 if (HitTestPoint(location)) { | 2248 if (HitTestPoint(location)) { |
| 2241 ConvertPointToScreen(this, &location); | 2249 ConvertPointToScreen(this, &location); |
| 2242 ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); | 2250 ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); |
| 2243 } | 2251 } |
| 2244 } else { | 2252 } else { |
| 2245 OnMouseReleased(event); | 2253 OnMouseReleased(event); |
| 2246 } | 2254 } |
| 2247 // WARNING: we may have been deleted. | 2255 // WARNING: we may have been deleted. |
| 2248 } | 2256 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 // especially important on X where we can get multiple mouse move events when | 2389 // especially important on X where we can get multiple mouse move events when |
| 2382 // we start the drag. | 2390 // we start the drag. |
| 2383 if (widget->dragged_view()) | 2391 if (widget->dragged_view()) |
| 2384 return false; | 2392 return false; |
| 2385 | 2393 |
| 2386 OSExchangeData data; | 2394 OSExchangeData data; |
| 2387 WriteDragData(press_pt, &data); | 2395 WriteDragData(press_pt, &data); |
| 2388 | 2396 |
| 2389 // Message the RootView to do the drag and drop. That way if we're removed | 2397 // Message the RootView to do the drag and drop. That way if we're removed |
| 2390 // the RootView can detect it and avoid calling us back. | 2398 // the RootView can detect it and avoid calling us back. |
| 2391 gfx::Point widget_location(event.location()); | 2399 gfx::Point widget_location(gfx::ToFlooredPoint(event.location())); |
| 2392 ConvertPointToWidget(this, &widget_location); | 2400 ConvertPointToWidget(this, &widget_location); |
| 2393 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2401 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2394 // WARNING: we may have been deleted. | 2402 // WARNING: we may have been deleted. |
| 2395 return true; | 2403 return true; |
| 2396 } | 2404 } |
| 2397 | 2405 |
| 2398 } // namespace views | 2406 } // namespace views |
| OLD | NEW |