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

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

Issue 12302005: views: Start sending mouse events using the EventDispatch interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.cc » ('j') | 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 #include "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 UpdateCursor(event); 401 UpdateCursor(event);
402 SetMouseLocationAndFlags(event); 402 SetMouseLocationAndFlags(event);
403 403
404 // If mouse_pressed_handler_ is non null, we are currently processing 404 // If mouse_pressed_handler_ is non null, we are currently processing
405 // a pressed -> drag -> released session. In that case we send the 405 // a pressed -> drag -> released session. In that case we send the
406 // event to mouse_pressed_handler_ 406 // event to mouse_pressed_handler_
407 if (mouse_pressed_handler_) { 407 if (mouse_pressed_handler_) {
408 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), 408 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this),
409 mouse_pressed_handler_); 409 mouse_pressed_handler_);
410 drag_info_.Reset(); 410 drag_info_.Reset();
411 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, 411 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event);
412 &drag_info_);
413 return true; 412 return true;
414 } 413 }
415 DCHECK(!explicit_mouse_handler_); 414 DCHECK(!explicit_mouse_handler_);
416 415
417 bool hit_disabled_view = false; 416 bool hit_disabled_view = false;
418 // Walk up the tree until we find a view that wants the mouse event. 417 // Walk up the tree until we find a view that wants the mouse event.
419 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location()); 418 for (mouse_pressed_handler_ = GetEventHandlerForPoint(event.location());
420 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); 419 mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
421 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { 420 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) {
422 DVLOG(1) << "OnMousePressed testing " 421 DVLOG(1) << "OnMousePressed testing "
423 << mouse_pressed_handler_->GetClassName(); 422 << mouse_pressed_handler_->GetClassName();
424 if (!mouse_pressed_handler_->enabled()) { 423 if (!mouse_pressed_handler_->enabled()) {
425 // Disabled views should eat events instead of propagating them upwards. 424 // Disabled views should eat events instead of propagating them upwards.
426 hit_disabled_view = true; 425 hit_disabled_view = true;
427 break; 426 break;
428 } 427 }
429 428
430 // See if this view wants to handle the mouse press. 429 // See if this view wants to handle the mouse press.
431 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this), 430 ui::MouseEvent mouse_pressed_event(event, static_cast<View*>(this),
432 mouse_pressed_handler_); 431 mouse_pressed_handler_);
433 432
434 // Remove the double-click flag if the handler is different than the 433 // Remove the double-click flag if the handler is different than the
435 // one which got the first click part of the double-click. 434 // one which got the first click part of the double-click.
436 if (mouse_pressed_handler_ != last_click_handler_) 435 if (mouse_pressed_handler_ != last_click_handler_)
437 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK); 436 mouse_pressed_event.set_flags(event.flags() & ~ui::EF_IS_DOUBLE_CLICK);
438 437
439 drag_info_.Reset(); 438 drag_info_.Reset();
440 bool handled = mouse_pressed_handler_->ProcessMousePressed( 439 bool handled = mouse_pressed_handler_->ProcessMousePressed(
441 mouse_pressed_event, &drag_info_); 440 mouse_pressed_event);
442 441
443 // The view could have removed itself from the tree when handling 442 // The view could have removed itself from the tree when handling
444 // OnMousePressed(). In this case, the removal notification will have 443 // OnMousePressed(). In this case, the removal notification will have
445 // reset mouse_pressed_handler_ to NULL out from under us. Detect this 444 // reset mouse_pressed_handler_ to NULL out from under us. Detect this
446 // case and stop. (See comments in view.h.) 445 // case and stop. (See comments in view.h.)
447 // 446 //
448 // NOTE: Don't return true here, because we don't want the frame to 447 // NOTE: Don't return true here, because we don't want the frame to
449 // forward future events to us when there's no handler. 448 // forward future events to us when there's no handler.
450 if (!mouse_pressed_handler_) 449 if (!mouse_pressed_handler_)
451 break; 450 break;
(...skipping 22 matching lines...) Expand all
474 last_click_handler_ = NULL; 473 last_click_handler_ = NULL;
475 return hit_disabled_view; 474 return hit_disabled_view;
476 } 475 }
477 476
478 bool RootView::OnMouseDragged(const ui::MouseEvent& event) { 477 bool RootView::OnMouseDragged(const ui::MouseEvent& event) {
479 if (mouse_pressed_handler_) { 478 if (mouse_pressed_handler_) {
480 SetMouseLocationAndFlags(event); 479 SetMouseLocationAndFlags(event);
481 480
482 ui::MouseEvent mouse_event(event, static_cast<View*>(this), 481 ui::MouseEvent mouse_event(event, static_cast<View*>(this),
483 mouse_pressed_handler_); 482 mouse_pressed_handler_);
484 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event, 483 return mouse_pressed_handler_->ProcessMouseDragged(mouse_event);
485 &drag_info_);
486 } 484 }
487 return false; 485 return false;
488 } 486 }
489 487
490 void RootView::OnMouseReleased(const ui::MouseEvent& event) { 488 void RootView::OnMouseReleased(const ui::MouseEvent& event) {
491 UpdateCursor(event); 489 UpdateCursor(event);
492 490
493 if (mouse_pressed_handler_) { 491 if (mouse_pressed_handler_) {
494 ui::MouseEvent mouse_released(event, static_cast<View*>(this), 492 ui::MouseEvent mouse_released(event, static_cast<View*>(this),
495 mouse_pressed_handler_); 493 mouse_pressed_handler_);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 } 642 }
645 643
646 gfx::Vector2d RootView::CalculateOffsetToAncestorWithLayer( 644 gfx::Vector2d RootView::CalculateOffsetToAncestorWithLayer(
647 ui::Layer** layer_parent) { 645 ui::Layer** layer_parent) {
648 gfx::Vector2d offset(View::CalculateOffsetToAncestorWithLayer(layer_parent)); 646 gfx::Vector2d offset(View::CalculateOffsetToAncestorWithLayer(layer_parent));
649 if (!layer()) 647 if (!layer())
650 offset += widget_->CalculateOffsetToAncestorWithLayer(layer_parent); 648 offset += widget_->CalculateOffsetToAncestorWithLayer(layer_parent);
651 return offset; 649 return offset;
652 } 650 }
653 651
652 View::DragInfo* RootView::GetDragInfo() {
653 return &drag_info_;
654 }
655
654 //////////////////////////////////////////////////////////////////////////////// 656 ////////////////////////////////////////////////////////////////////////////////
655 // RootView, private: 657 // RootView, private:
656 658
657 // Input ----------------------------------------------------------------------- 659 // Input -----------------------------------------------------------------------
658 660
659 void RootView::UpdateCursor(const ui::MouseEvent& event) { 661 void RootView::UpdateCursor(const ui::MouseEvent& event) {
660 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { 662 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
661 View* v = GetEventHandlerForPoint(event.location()); 663 View* v = GetEventHandlerForPoint(event.location());
662 ui::MouseEvent me(event, static_cast<View*>(this), v); 664 ui::MouseEvent me(event, static_cast<View*>(this), v);
663 widget_->SetCursor(v->GetCursor(me)); 665 widget_->SetCursor(v->GetCursor(me));
(...skipping 12 matching lines...) Expand all
676 if (DispatchEvent(target, event)) 678 if (DispatchEvent(target, event))
677 event_dispatch_target_ = old_target; 679 event_dispatch_target_ = old_target;
678 } 680 }
679 681
680 bool RootView::CanDispatchToTarget(ui::EventTarget* target) { 682 bool RootView::CanDispatchToTarget(ui::EventTarget* target) {
681 return event_dispatch_target_ == target; 683 return event_dispatch_target_ == target;
682 } 684 }
683 685
684 } // namespace internal 686 } // namespace internal
685 } // namespace views 687 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698