Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: ui/views/view.cc

Issue 12395010: Context menu on views must show on mouse dpwn for non-WIN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 const bool kContextMenuOnMousePress = false;
62 #else
63 const bool kContextMenuOnMousePress = 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 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 2037
2032 // Input ----------------------------------------------------------------------- 2038 // Input -----------------------------------------------------------------------
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;
2047 View::DragInfo* drag_info = GetDragInfo();
2041 2048
2042 const bool enabled = enabled_; 2049 const bool enabled = enabled_;
2043 const bool result = OnMousePressed(event); 2050 const bool result = OnMousePressed(event);
2044 // WARNING: we may have been deleted, don't use any View variables. 2051 // WARNING: we may have been deleted, don't use any View variables.
2045 2052
2046 if (!enabled) 2053 if (!enabled)
2047 return result; 2054 return result;
2048 2055
2056 // Assume that if there is a context menu controller we won't be deleted
2057 // from mouse pressed.
2058 if (event.IsOnlyRightMouseButton() && context_menu_controller &&
2059 kContextMenuOnMousePress) {
2060 gfx::Point location(event.location());
2061 if (HitTestPoint(location)) {
2062 ConvertPointToScreen(this, &location);
2063 ShowContextMenu(location, true);
2064 return true;
2065 }
2066 }
2067
2049 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { 2068 if (drag_operations != ui::DragDropTypes::DRAG_NONE) {
2050 GetDragInfo()->PossibleDrag(event.location()); 2069 drag_info->PossibleDrag(event.location());
2051 return true; 2070 return true;
2052 } 2071 }
2053 return !!context_menu_controller || result; 2072 return !!context_menu_controller || result;
2054 } 2073 }
2055 2074
2056 bool View::ProcessMouseDragged(const ui::MouseEvent& event) { 2075 bool View::ProcessMouseDragged(const ui::MouseEvent& event) {
2057 // Copy the field, that way if we're deleted after drag and drop no harm is 2076 // Copy the field, that way if we're deleted after drag and drop no harm is
2058 // done. 2077 // done.
2059 ContextMenuController* context_menu_controller = context_menu_controller_; 2078 ContextMenuController* context_menu_controller = context_menu_controller_;
2060 const bool possible_drag = GetDragInfo()->possible_drag; 2079 const bool possible_drag = GetDragInfo()->possible_drag;
2061 if (possible_drag && 2080 if (possible_drag &&
2062 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) { 2081 ExceededDragThreshold(GetDragInfo()->start_pt - event.location())) {
2063 if (!drag_controller_ || 2082 if (!drag_controller_ ||
2064 drag_controller_->CanStartDragForView( 2083 drag_controller_->CanStartDragForView(
2065 this, GetDragInfo()->start_pt, event.location())) { 2084 this, GetDragInfo()->start_pt, event.location())) {
2066 DoDrag(event, GetDragInfo()->start_pt, 2085 DoDrag(event, GetDragInfo()->start_pt,
2067 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); 2086 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
2068 } 2087 }
2069 } else { 2088 } else {
2070 if (OnMouseDragged(event)) 2089 if (OnMouseDragged(event))
2071 return true; 2090 return true;
2072 // Fall through to return value based on context menu controller. 2091 // Fall through to return value based on context menu controller.
2073 } 2092 }
2074 // WARNING: we may have been deleted. 2093 // WARNING: we may have been deleted.
2075 return (context_menu_controller != NULL) || possible_drag; 2094 return (context_menu_controller != NULL) || possible_drag;
2076 } 2095 }
2077 2096
2078 void View::ProcessMouseReleased(const ui::MouseEvent& event) { 2097 void View::ProcessMouseReleased(const ui::MouseEvent& event) {
2079 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { 2098 if (!kContextMenuOnMousePress && context_menu_controller_ &&
2099 event.IsOnlyRightMouseButton()) {
2080 // Assume that if there is a context menu controller we won't be deleted 2100 // Assume that if there is a context menu controller we won't be deleted
2081 // from mouse released. 2101 // from mouse released.
2082 gfx::Point location(event.location()); 2102 gfx::Point location(event.location());
2083 OnMouseReleased(event); 2103 OnMouseReleased(event);
2084 if (HitTestPoint(location)) { 2104 if (HitTestPoint(location)) {
2085 ConvertPointToScreen(this, &location); 2105 ConvertPointToScreen(this, &location);
2086 ShowContextMenu(location, true); 2106 ShowContextMenu(location, true);
2087 } 2107 }
2088 } else { 2108 } else {
2089 OnMouseReleased(event); 2109 OnMouseReleased(event);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 ConvertPointToWidget(this, &widget_location); 2250 ConvertPointToWidget(this, &widget_location);
2231 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, 2251 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations,
2232 source); 2252 source);
2233 return true; 2253 return true;
2234 #else 2254 #else
2235 return false; 2255 return false;
2236 #endif // !defined(OS_MACOSX) 2256 #endif // !defined(OS_MACOSX)
2237 } 2257 }
2238 2258
2239 } // namespace views 2259 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698