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

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

Issue 560053002: Do not interchange MOUSE_MOVED and MOUSE_DRAGGED events in Widget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 6 years, 2 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
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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET), 161 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
162 is_secondary_widget_(true), 162 is_secondary_widget_(true),
163 frame_type_(FRAME_TYPE_DEFAULT), 163 frame_type_(FRAME_TYPE_DEFAULT),
164 disable_inactive_rendering_(false), 164 disable_inactive_rendering_(false),
165 widget_closed_(false), 165 widget_closed_(false),
166 saved_show_state_(ui::SHOW_STATE_DEFAULT), 166 saved_show_state_(ui::SHOW_STATE_DEFAULT),
167 focus_on_creation_(true), 167 focus_on_creation_(true),
168 is_top_level_(false), 168 is_top_level_(false),
169 native_widget_initialized_(false), 169 native_widget_initialized_(false),
170 native_widget_destroyed_(false), 170 native_widget_destroyed_(false),
171 is_mouse_button_pressed_(false),
172 ignore_capture_loss_(false), 171 ignore_capture_loss_(false),
173 last_mouse_event_was_move_(false), 172 last_mouse_event_was_move_(false),
174 auto_release_capture_(true), 173 auto_release_capture_(true),
175 root_layers_dirty_(false), 174 root_layers_dirty_(false),
176 movement_disabled_(false), 175 movement_disabled_(false),
177 observer_manager_(this) { 176 observer_manager_(this) {
178 } 177 }
179 178
180 Widget::~Widget() { 179 Widget::~Widget() {
181 DestroyRootView(); 180 DestroyRootView();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 343
345 widget_delegate_ = params.delegate ? 344 widget_delegate_ = params.delegate ?
346 params.delegate : new DefaultWidgetDelegate(this); 345 params.delegate : new DefaultWidgetDelegate(this);
347 widget_delegate_->set_can_activate(can_activate); 346 widget_delegate_->set_can_activate(can_activate);
348 347
349 ownership_ = params.ownership; 348 ownership_ = params.ownership;
350 native_widget_ = CreateNativeWidget(params.native_widget, this)-> 349 native_widget_ = CreateNativeWidget(params.native_widget, this)->
351 AsNativeWidgetPrivate(); 350 AsNativeWidgetPrivate();
352 root_view_.reset(CreateRootView()); 351 root_view_.reset(CreateRootView());
353 default_theme_provider_.reset(new ui::DefaultThemeProvider); 352 default_theme_provider_.reset(new ui::DefaultThemeProvider);
354 if (params.type == InitParams::TYPE_MENU) {
355 is_mouse_button_pressed_ =
356 internal::NativeWidgetPrivate::IsMouseButtonDown();
357 }
358 native_widget_->InitNativeWidget(params); 353 native_widget_->InitNativeWidget(params);
359 if (RequiresNonClientView(params.type)) { 354 if (RequiresNonClientView(params.type)) {
360 non_client_view_ = new NonClientView; 355 non_client_view_ = new NonClientView;
361 non_client_view_->SetFrameView(CreateNonClientFrameView()); 356 non_client_view_->SetFrameView(CreateNonClientFrameView());
362 // Create the ClientView, add it to the NonClientView and add the 357 // Create the ClientView, add it to the NonClientView and add the
363 // NonClientView to the RootView. This will cause everything to be parented. 358 // NonClientView to the RootView. This will cause everything to be parented.
364 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); 359 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
365 non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView()); 360 non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView());
366 SetContentsView(non_client_view_); 361 SetContentsView(non_client_view_);
367 // Initialize the window's title before setting the window's initial bounds; 362 // Initialize the window's title before setting the window's initial bounds;
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 936
942 void Widget::SetCapture(View* view) { 937 void Widget::SetCapture(View* view) {
943 if (!native_widget_->HasCapture()) { 938 if (!native_widget_->HasCapture()) {
944 native_widget_->SetCapture(); 939 native_widget_->SetCapture();
945 940
946 // Early return if setting capture was unsuccessful. 941 // Early return if setting capture was unsuccessful.
947 if (!native_widget_->HasCapture()) 942 if (!native_widget_->HasCapture())
948 return; 943 return;
949 } 944 }
950 945
951 if (internal::NativeWidgetPrivate::IsMouseButtonDown())
952 is_mouse_button_pressed_ = true;
953 root_view_->SetMouseHandler(view); 946 root_view_->SetMouseHandler(view);
954 } 947 }
955 948
956 void Widget::ReleaseCapture() { 949 void Widget::ReleaseCapture() {
957 if (native_widget_->HasCapture()) 950 if (native_widget_->HasCapture())
958 native_widget_->ReleaseCapture(); 951 native_widget_->ReleaseCapture();
959 } 952 }
960 953
961 bool Widget::HasCapture() { 954 bool Widget::HasCapture() {
962 return native_widget_->HasCapture(); 955 return native_widget_->HasCapture();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 } 1176 }
1184 1177
1185 void Widget::OnKeyEvent(ui::KeyEvent* event) { 1178 void Widget::OnKeyEvent(ui::KeyEvent* event) {
1186 SendEventToProcessor(event); 1179 SendEventToProcessor(event);
1187 } 1180 }
1188 1181
1189 // TODO(tdanderson): We should not be calling the OnMouse*() functions on 1182 // TODO(tdanderson): We should not be calling the OnMouse*() functions on
1190 // RootView from anywhere in Widget. Use 1183 // RootView from anywhere in Widget. Use
1191 // SendEventToProcessor() instead. See crbug.com/348087. 1184 // SendEventToProcessor() instead. See crbug.com/348087.
1192 void Widget::OnMouseEvent(ui::MouseEvent* event) { 1185 void Widget::OnMouseEvent(ui::MouseEvent* event) {
1186 if (event->type() != ui::ET_MOUSE_MOVED)
1187 last_mouse_event_was_move_ = false;
1188
1193 View* root_view = GetRootView(); 1189 View* root_view = GetRootView();
1194 switch (event->type()) { 1190 switch (event->type()) {
1195 case ui::ET_MOUSE_PRESSED: { 1191 case ui::ET_MOUSE_PRESSED: {
1196 last_mouse_event_was_move_ = false;
1197
1198 // We may get deleted by the time we return from OnMousePressed. So we 1192 // We may get deleted by the time we return from OnMousePressed. So we
1199 // use an observer to make sure we are still alive. 1193 // use an observer to make sure we are still alive.
1200 WidgetDeletionObserver widget_deletion_observer(this); 1194 WidgetDeletionObserver widget_deletion_observer(this);
1201 1195
1202 // Make sure we're still visible before we attempt capture as the mouse 1196 // Make sure we're still visible before we attempt capture as the mouse
1203 // press processing may have made the window hide (as happens with menus). 1197 // press processing may have made the window hide (as happens with menus).
1204 1198
1205 // It is possible for a View to show a context menu on mouse-press. Since 1199 // It is possible for a View to show a context menu on mouse-press. Since
1206 // the menu does a capture and starts a nested message-loop, the release 1200 // the menu does a capture and starts a nested message-loop, the release
1207 // would go to the menu. The next click (i.e. both mouse-press and release 1201 // would go to the menu. The next click (i.e. both mouse-press and release
1208 // events) also go to the menu. The menu (and the nested message-loop) 1202 // events) also go to the menu. The menu (and the nested message-loop)
1209 // gets closed after this second release event. The code then resumes from 1203 // gets closed after this second release event. The code then resumes from
1210 // here. So make sure that the mouse-button is still down before doing a 1204 // here. So make sure that the mouse-button is still down before doing a
1211 // capture. 1205 // capture.
1212 if (root_view && root_view->OnMousePressed(*event) && 1206 if (root_view && root_view->OnMousePressed(*event) &&
1213 widget_deletion_observer.IsWidgetAlive() && IsVisible() && 1207 widget_deletion_observer.IsWidgetAlive() && IsVisible() &&
1214 internal::NativeWidgetPrivate::IsMouseButtonDown()) { 1208 internal::NativeWidgetPrivate::IsMouseButtonDown()) {
1215 is_mouse_button_pressed_ = true;
1216 if (!native_widget_->HasCapture()) 1209 if (!native_widget_->HasCapture())
1217 native_widget_->SetCapture(); 1210 native_widget_->SetCapture();
1218 event->SetHandled(); 1211 event->SetHandled();
1219 } 1212 }
1220 return; 1213 return;
1221 } 1214 }
1222 1215
1223 case ui::ET_MOUSE_RELEASED: 1216 case ui::ET_MOUSE_RELEASED:
1224 last_mouse_event_was_move_ = false;
1225 is_mouse_button_pressed_ = false;
1226 // Release capture first, to avoid confusion if OnMouseReleased blocks. 1217 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1227 if (auto_release_capture_ && native_widget_->HasCapture()) { 1218 if (auto_release_capture_ && native_widget_->HasCapture()) {
1228 base::AutoReset<bool> resetter(&ignore_capture_loss_, true); 1219 base::AutoReset<bool> resetter(&ignore_capture_loss_, true);
1229 native_widget_->ReleaseCapture(); 1220 native_widget_->ReleaseCapture();
1230 } 1221 }
1231 if (root_view) 1222 if (root_view)
1232 root_view->OnMouseReleased(*event); 1223 root_view->OnMouseReleased(*event);
1233 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0) 1224 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
1234 event->SetHandled(); 1225 event->SetHandled();
1235 return; 1226 return;
1236 1227
1237 case ui::ET_MOUSE_MOVED: 1228 case ui::ET_MOUSE_MOVED:
1238 case ui::ET_MOUSE_DRAGGED: 1229 if (!last_mouse_event_was_move_ ||
1239 if (native_widget_->HasCapture() && is_mouse_button_pressed_) { 1230 last_mouse_event_position_ != event->location()) {
1240 last_mouse_event_was_move_ = false;
1241 if (root_view)
1242 root_view->OnMouseDragged(*event);
1243 } else if (!last_mouse_event_was_move_ ||
1244 last_mouse_event_position_ != event->location()) {
1245 last_mouse_event_position_ = event->location(); 1231 last_mouse_event_position_ = event->location();
1246 last_mouse_event_was_move_ = true; 1232 last_mouse_event_was_move_ = true;
1247 if (root_view) 1233 if (root_view)
1248 root_view->OnMouseMoved(*event); 1234 root_view->OnMouseMoved(*event);
1249 } 1235 }
1250 return; 1236 return;
1251 1237
1238 case ui::ET_MOUSE_DRAGGED:
1239 if (root_view)
1240 root_view->OnMouseDragged(*event);
1241 return;
1242
1252 case ui::ET_MOUSE_EXITED: 1243 case ui::ET_MOUSE_EXITED:
1253 last_mouse_event_was_move_ = false;
1254 if (root_view) 1244 if (root_view)
1255 root_view->OnMouseExited(*event); 1245 root_view->OnMouseExited(*event);
1256 return; 1246 return;
1257 1247
1258 case ui::ET_MOUSEWHEEL: 1248 case ui::ET_MOUSEWHEEL:
1259 if (root_view && root_view->OnMouseWheel( 1249 if (root_view && root_view->OnMouseWheel(
1260 static_cast<const ui::MouseWheelEvent&>(*event))) 1250 static_cast<const ui::MouseWheelEvent&>(*event)))
1261 event->SetHandled(); 1251 event->SetHandled();
1262 return; 1252 return;
1263 1253
1264 default: 1254 default:
1265 return; 1255 return;
1266 } 1256 }
1267 } 1257 }
1268 1258
1269 void Widget::OnMouseCaptureLost() { 1259 void Widget::OnMouseCaptureLost() {
1270 if (ignore_capture_loss_) 1260 if (ignore_capture_loss_)
1271 return; 1261 return;
1272 1262
1273 View* root_view = GetRootView(); 1263 View* root_view = GetRootView();
1274 if (root_view) 1264 if (root_view)
1275 root_view->OnMouseCaptureLost(); 1265 root_view->OnMouseCaptureLost();
1276 is_mouse_button_pressed_ = false;
1277 } 1266 }
1278 1267
1279 void Widget::OnScrollEvent(ui::ScrollEvent* event) { 1268 void Widget::OnScrollEvent(ui::ScrollEvent* event) {
1280 ui::ScrollEvent event_copy(*event); 1269 ui::ScrollEvent event_copy(*event);
1281 SendEventToProcessor(&event_copy); 1270 SendEventToProcessor(&event_copy);
1282 1271
1283 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events. 1272 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events.
1284 if (!event_copy.handled() && event_copy.type() == ui::ET_SCROLL) { 1273 if (!event_copy.handled() && event_copy.type() == ui::ET_SCROLL) {
1285 ui::MouseWheelEvent wheel(*event); 1274 ui::MouseWheelEvent wheel(*event);
1286 OnMouseEvent(&wheel); 1275 OnMouseEvent(&wheel);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 1510
1522 //////////////////////////////////////////////////////////////////////////////// 1511 ////////////////////////////////////////////////////////////////////////////////
1523 // internal::NativeWidgetPrivate, NativeWidget implementation: 1512 // internal::NativeWidgetPrivate, NativeWidget implementation:
1524 1513
1525 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1514 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1526 return this; 1515 return this;
1527 } 1516 }
1528 1517
1529 } // namespace internal 1518 } // namespace internal
1530 } // namespace views 1519 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698