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

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

Issue 12529012: Context menu on views must show on mouse down for non-WIN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 years, 8 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
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 #include "ui/views/widget/widget.h" 5 #include "ui/views/widget/widget.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return can_activate_; 119 return can_activate_;
120 } 120 }
121 121
122 private: 122 private:
123 Widget* widget_; 123 Widget* widget_;
124 bool can_activate_; 124 bool can_activate_;
125 125
126 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate); 126 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate);
127 }; 127 };
128 128
129 class Widget::PostMousePressedProcessor : public WidgetObserver {
130 public:
131 explicit PostMousePressedProcessor(views::Widget* owner) : owner_(owner) {
132 owner_->AddObserver(this);
133 }
134
135 virtual ~PostMousePressedProcessor() {
136 CleanupOwner();
137 }
138
139 void DoPostMousePressedProcessing() {
140 // Make sure we're still visible before we attempt capture as the mouse
141 // press processing may have made the window hide (as happens with menus).
142 if (!owner_ || !owner_->IsVisible())
143 return;
144
145 owner_->is_mouse_button_pressed_ = true;
146
147 // OnNativeWidgetDestroying also notifies all
148 // WidgetObservers::OnWidgetDestroying. So we can be sure that if |owner_|
149 // is non-NULL, |owner_->native_widget_| will also be non-NULL.
150 if (!owner_->native_widget_private()->HasCapture())
151 owner_->native_widget_private()->SetCapture();
152 }
153
154 // Overridden from WidgetObserver.
155 virtual void OnWidgetDestroying(Widget* widget) OVERRIDE {
156 CleanupOwner();
157 }
158
159 private:
160 void CleanupOwner() {
161 if (owner_) {
162 owner_->RemoveObserver(this);
163 owner_ = NULL;
164 }
165 }
166
167 views::Widget* owner_;
168
169 DISALLOW_COPY_AND_ASSIGN(PostMousePressedProcessor);
170 };
171
129 //////////////////////////////////////////////////////////////////////////////// 172 ////////////////////////////////////////////////////////////////////////////////
130 // Widget, InitParams: 173 // Widget, InitParams:
131 174
132 Widget::InitParams::InitParams() 175 Widget::InitParams::InitParams()
133 : type(TYPE_WINDOW), 176 : type(TYPE_WINDOW),
134 delegate(NULL), 177 delegate(NULL),
135 child(false), 178 child(false),
136 transient(false), 179 transient(false),
137 transparent(ViewsDelegate::views_delegate && 180 transparent(ViewsDelegate::views_delegate &&
138 ViewsDelegate::views_delegate->UseTransparentWindows()), 181 ViewsDelegate::views_delegate->UseTransparentWindows()),
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 void Widget::OnKeyEvent(ui::KeyEvent* event) { 1187 void Widget::OnKeyEvent(ui::KeyEvent* event) {
1145 ScopedEvent scoped(this, *event); 1188 ScopedEvent scoped(this, *event);
1146 static_cast<internal::RootView*>(GetRootView())-> 1189 static_cast<internal::RootView*>(GetRootView())->
1147 DispatchKeyEvent(event); 1190 DispatchKeyEvent(event);
1148 } 1191 }
1149 1192
1150 void Widget::OnMouseEvent(ui::MouseEvent* event) { 1193 void Widget::OnMouseEvent(ui::MouseEvent* event) {
1151 ScopedEvent scoped(this, *event); 1194 ScopedEvent scoped(this, *event);
1152 View* root_view = GetRootView(); 1195 View* root_view = GetRootView();
1153 switch (event->type()) { 1196 switch (event->type()) {
1154 case ui::ET_MOUSE_PRESSED: 1197 case ui::ET_MOUSE_PRESSED: {
1155 last_mouse_event_was_move_ = false; 1198 last_mouse_event_was_move_ = false;
1156 // Make sure we're still visible before we attempt capture as the mouse 1199
1157 // press processing may have made the window hide (as happens with menus). 1200 // We may get deleted by the time we return from OnMousePressed. So we
1158 if (root_view && root_view->OnMousePressed(*event) && IsVisible()) { 1201 // use an observer to do capture after OnMousePressed in a safe way.
1159 is_mouse_button_pressed_ = true; 1202 PostMousePressedProcessor post_mouse_pressed_processor(this);
1160 if (!native_widget_->HasCapture()) 1203 if (root_view && root_view->OnMousePressed(*event)) {
1161 native_widget_->SetCapture(); 1204 post_mouse_pressed_processor.DoPostMousePressedProcessing();
1162 event->SetHandled(); 1205 event->SetHandled();
1163 } 1206 }
1164 return; 1207 return;
1208 }
1165 case ui::ET_MOUSE_RELEASED: 1209 case ui::ET_MOUSE_RELEASED:
1166 last_mouse_event_was_move_ = false; 1210 last_mouse_event_was_move_ = false;
1167 is_mouse_button_pressed_ = false; 1211 is_mouse_button_pressed_ = false;
1168 // Release capture first, to avoid confusion if OnMouseReleased blocks. 1212 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1169 if (native_widget_->HasCapture() && 1213 if (native_widget_->HasCapture() &&
1170 ShouldReleaseCaptureOnMouseReleased()) { 1214 ShouldReleaseCaptureOnMouseReleased()) {
1171 native_widget_->ReleaseCapture(); 1215 native_widget_->ReleaseCapture();
1172 } 1216 }
1173 if (root_view) 1217 if (root_view)
1174 root_view->OnMouseReleased(*event); 1218 root_view->OnMouseReleased(*event);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 1473
1430 //////////////////////////////////////////////////////////////////////////////// 1474 ////////////////////////////////////////////////////////////////////////////////
1431 // internal::NativeWidgetPrivate, NativeWidget implementation: 1475 // internal::NativeWidgetPrivate, NativeWidget implementation:
1432 1476
1433 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1477 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1434 return this; 1478 return this;
1435 } 1479 }
1436 1480
1437 } // namespace internal 1481 } // namespace internal
1438 } // namespace views 1482 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698