Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 // Whether to use accelerated compositing when necessary (e.g. when a view has a | 52 // Whether to use accelerated compositing when necessary (e.g. when a view has a |
| 53 // transformation). | 53 // transformation). |
| 54 #if defined(USE_AURA) | 54 #if defined(USE_AURA) |
| 55 bool use_acceleration_when_possible = true; | 55 bool use_acceleration_when_possible = true; |
| 56 #else | 56 #else |
| 57 bool use_acceleration_when_possible = false; | 57 bool use_acceleration_when_possible = false; |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 #if defined(OS_WIN) | |
| 61 bool context_menu_on_mouse_press = false; | |
| 62 #else | |
| 63 bool context_menu_on_mouse_press = true; | |
| 64 #endif | |
| 65 | |
| 60 // Saves the drawing state, and restores the state when going out of scope. | 66 // Saves the drawing state, and restores the state when going out of scope. |
| 61 class ScopedCanvas { | 67 class ScopedCanvas { |
| 62 public: | 68 public: |
| 63 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { | 69 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
| 64 if (canvas_) | 70 if (canvas_) |
| 65 canvas_->Save(); | 71 canvas_->Save(); |
| 66 } | 72 } |
| 67 ~ScopedCanvas() { | 73 ~ScopedCanvas() { |
| 68 if (canvas_) | 74 if (canvas_) |
| 69 canvas_->Restore(); | 75 canvas_->Restore(); |
| (...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2039 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 2045 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
| 2040 context_menu_controller_ : 0; | 2046 context_menu_controller_ : 0; |
| 2041 | 2047 |
| 2042 const bool enabled = enabled_; | 2048 const bool enabled = enabled_; |
| 2043 const bool result = OnMousePressed(event); | 2049 const bool result = OnMousePressed(event); |
| 2044 // WARNING: we may have been deleted, don't use any View variables. | 2050 // WARNING: we may have been deleted, don't use any View variables. |
| 2045 | 2051 |
| 2046 if (!enabled) | 2052 if (!enabled) |
| 2047 return result; | 2053 return result; |
| 2048 | 2054 |
| 2055 if (event.IsOnlyRightMouseButton() && context_menu_controller_ && | |
| 2056 context_menu_on_mouse_press) { | |
|
sadrul
2013/03/04 23:22:04
Note the WARNING on 2050.
I think you should firs
varunjain
2013/03/05 00:04:28
Ha! I missed that warning. Although, the GetDragIn
sadrul
2013/03/05 16:30:11
Good catch. Perhaps GetDragInfo() should be cached
varunjain
2013/03/05 21:14:21
Done.
| |
| 2057 gfx::Point location(event.location()); | |
| 2058 if (HitTestPoint(location)) { | |
| 2059 ConvertPointToScreen(this, &location); | |
| 2060 ShowContextMenu(location, true); | |
| 2061 return true; | |
| 2062 } | |
| 2063 } | |
| 2064 | |
| 2049 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 2065 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
| 2050 GetDragInfo()->PossibleDrag(event.location()); | 2066 GetDragInfo()->PossibleDrag(event.location()); |
| 2051 return true; | 2067 return true; |
| 2052 } | 2068 } |
| 2053 return !!context_menu_controller || result; | 2069 return !!context_menu_controller || result; |
| 2054 } | 2070 } |
| 2055 | 2071 |
| 2056 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { | 2072 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { |
| 2057 // Copy the field, that way if we're deleted after drag and drop no harm is | 2073 // Copy the field, that way if we're deleted after drag and drop no harm is |
| 2058 // done. | 2074 // done. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2069 } else { | 2085 } else { |
| 2070 if (OnMouseDragged(event)) | 2086 if (OnMouseDragged(event)) |
| 2071 return true; | 2087 return true; |
| 2072 // Fall through to return value based on context menu controller. | 2088 // Fall through to return value based on context menu controller. |
| 2073 } | 2089 } |
| 2074 // WARNING: we may have been deleted. | 2090 // WARNING: we may have been deleted. |
| 2075 return (context_menu_controller != NULL) || possible_drag; | 2091 return (context_menu_controller != NULL) || possible_drag; |
| 2076 } | 2092 } |
| 2077 | 2093 |
| 2078 void View::ProcessMouseReleased(const ui::MouseEvent& event) { | 2094 void View::ProcessMouseReleased(const ui::MouseEvent& event) { |
| 2079 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { | 2095 if (!context_menu_on_mouse_press && context_menu_controller_ && |
| 2096 event.IsOnlyRightMouseButton()) { | |
| 2080 // Assume that if there is a context menu controller we won't be deleted | 2097 // Assume that if there is a context menu controller we won't be deleted |
| 2081 // from mouse released. | 2098 // from mouse released. |
| 2082 gfx::Point location(event.location()); | 2099 gfx::Point location(event.location()); |
| 2083 OnMouseReleased(event); | 2100 OnMouseReleased(event); |
| 2084 if (HitTestPoint(location)) { | 2101 if (HitTestPoint(location)) { |
| 2085 ConvertPointToScreen(this, &location); | 2102 ConvertPointToScreen(this, &location); |
| 2086 ShowContextMenu(location, true); | 2103 ShowContextMenu(location, true); |
| 2087 } | 2104 } |
| 2088 } else { | 2105 } else { |
| 2089 OnMouseReleased(event); | 2106 OnMouseReleased(event); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2230 ConvertPointToWidget(this, &widget_location); | 2247 ConvertPointToWidget(this, &widget_location); |
| 2231 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2248 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
| 2232 source); | 2249 source); |
| 2233 return true; | 2250 return true; |
| 2234 #else | 2251 #else |
| 2235 return false; | 2252 return false; |
| 2236 #endif // !defined(OS_MACOSX) | 2253 #endif // !defined(OS_MACOSX) |
| 2237 } | 2254 } |
| 2238 | 2255 |
| 2239 } // namespace views | 2256 } // namespace views |
| OLD | NEW |