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; | |
sadrul
2013/03/05 16:30:11
this value never changes, right? It should be 'con
varunjain
2013/03/05 21:14:21
Done.
| |
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 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2033 | 2039 |
2034 bool View::ProcessMousePressed(const ui::MouseEvent& event) { | 2040 bool View::ProcessMousePressed(const ui::MouseEvent& event) { |
2035 int drag_operations = | 2041 int drag_operations = |
2036 (enabled_ && event.IsOnlyLeftMouseButton() && | 2042 (enabled_ && event.IsOnlyLeftMouseButton() && |
2037 HitTestPoint(event.location())) ? | 2043 HitTestPoint(event.location())) ? |
2038 GetDragOperations(event.location()) : 0; | 2044 GetDragOperations(event.location()) : 0; |
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 |
2044 // WARNING: we may have been deleted, don't use any View variables. | 2050 bool result = false; |
2051 if (enabled_ && context_menu_controller_ && event.IsOnlyRightMouseButton() && | |
2052 context_menu_on_mouse_press) { | |
2053 // Assume that if there is a context menu controller we won't be deleted | |
2054 // from mouse pressed. | |
2055 gfx::Point location(event.location()); | |
2056 result = OnMousePressed(event); | |
2057 if (HitTestPoint(location)) { | |
2058 ConvertPointToScreen(this, &location); | |
2059 ShowContextMenu(location, true); | |
2060 return true; | |
2061 } | |
2062 } else { | |
2063 result = OnMousePressed(event); | |
2064 // WARNING: we may have been deleted, don't use any View variables. | |
2065 } | |
2045 | 2066 |
2046 if (!enabled) | 2067 if (!enabled) |
2047 return result; | 2068 return result; |
2048 | 2069 |
2049 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 2070 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
2050 GetDragInfo()->PossibleDrag(event.location()); | 2071 GetDragInfo()->PossibleDrag(event.location()); |
2051 return true; | 2072 return true; |
2052 } | 2073 } |
2053 return !!context_menu_controller || result; | 2074 return !!context_menu_controller || result; |
2054 } | 2075 } |
(...skipping 14 matching lines...) Expand all Loading... | |
2069 } else { | 2090 } else { |
2070 if (OnMouseDragged(event)) | 2091 if (OnMouseDragged(event)) |
2071 return true; | 2092 return true; |
2072 // Fall through to return value based on context menu controller. | 2093 // Fall through to return value based on context menu controller. |
2073 } | 2094 } |
2074 // WARNING: we may have been deleted. | 2095 // WARNING: we may have been deleted. |
2075 return (context_menu_controller != NULL) || possible_drag; | 2096 return (context_menu_controller != NULL) || possible_drag; |
2076 } | 2097 } |
2077 | 2098 |
2078 void View::ProcessMouseReleased(const ui::MouseEvent& event) { | 2099 void View::ProcessMouseReleased(const ui::MouseEvent& event) { |
2079 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { | 2100 if (!context_menu_on_mouse_press && context_menu_controller_ && |
2101 event.IsOnlyRightMouseButton()) { | |
2080 // Assume that if there is a context menu controller we won't be deleted | 2102 // Assume that if there is a context menu controller we won't be deleted |
2081 // from mouse released. | 2103 // from mouse released. |
2082 gfx::Point location(event.location()); | 2104 gfx::Point location(event.location()); |
2083 OnMouseReleased(event); | 2105 OnMouseReleased(event); |
2084 if (HitTestPoint(location)) { | 2106 if (HitTestPoint(location)) { |
2085 ConvertPointToScreen(this, &location); | 2107 ConvertPointToScreen(this, &location); |
2086 ShowContextMenu(location, true); | 2108 ShowContextMenu(location, true); |
2087 } | 2109 } |
2088 } else { | 2110 } else { |
2089 OnMouseReleased(event); | 2111 OnMouseReleased(event); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2230 ConvertPointToWidget(this, &widget_location); | 2252 ConvertPointToWidget(this, &widget_location); |
2231 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2253 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2232 source); | 2254 source); |
2233 return true; | 2255 return true; |
2234 #else | 2256 #else |
2235 return false; | 2257 return false; |
2236 #endif // !defined(OS_MACOSX) | 2258 #endif // !defined(OS_MACOSX) |
2237 } | 2259 } |
2238 | 2260 |
2239 } // namespace views | 2261 } // namespace views |
OLD | NEW |