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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller2.cc

Issue 10021029: Propagate OnNativeWidgetMove to delegate/observers, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add/remove anchor observer OnWidgetVisibilityChanged; clear anchor_view_ OnWidgetClosing. Created 8 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller2.h ('k') | chrome/chrome_browser.gypi » ('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 "chrome/browser/ui/views/tabs/tab_drag_controller2.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller2.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 20 matching lines...) Expand all
31 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "ui/base/animation/animation.h" 32 #include "ui/base/animation/animation.h"
33 #include "ui/base/animation/animation_delegate.h" 33 #include "ui/base/animation/animation_delegate.h"
34 #include "ui/base/animation/slide_animation.h" 34 #include "ui/base/animation/slide_animation.h"
35 #include "ui/base/events.h" 35 #include "ui/base/events.h"
36 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
37 #include "ui/gfx/canvas.h" 37 #include "ui/gfx/canvas.h"
38 #include "ui/gfx/screen.h" 38 #include "ui/gfx/screen.h"
39 #include "ui/views/events/event.h" 39 #include "ui/views/events/event.h"
40 #include "ui/views/widget/root_view.h" 40 #include "ui/views/widget/root_view.h"
41 #include "ui/views/widget/widget.h"
42 41
43 #if defined(USE_ASH) 42 #if defined(USE_ASH)
44 #include "ash/wm/property_util.h" 43 #include "ash/wm/property_util.h"
45 #endif 44 #endif
46 45
47 using content::UserMetricsAction; 46 using content::UserMetricsAction;
48 using content::WebContents; 47 using content::WebContents;
49 48
50 static const int kHorizontalMoveThreshold = 16; // Pixels. 49 static const int kHorizontalMoveThreshold = 16; // Pixels.
51 50
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 319 }
321 320
322 TabDragController2::~TabDragController2() { 321 TabDragController2::~TabDragController2() {
323 if (instance_ == this) 322 if (instance_ == this)
324 instance_ = NULL; 323 instance_ = NULL;
325 324
326 if (destroyed_) 325 if (destroyed_)
327 *destroyed_ = true; 326 *destroyed_ = true;
328 327
329 if (move_loop_browser_view_) { 328 if (move_loop_browser_view_) {
330 move_loop_browser_view_->set_move_observer(NULL); 329 views::Widget* browser_widget = move_loop_browser_view_->GetWidget();
331 SetTrackedByWorkspace( 330 browser_widget->RemoveObserver(this);
332 move_loop_browser_view_->GetWidget()->GetNativeView(), true); 331 SetTrackedByWorkspace(browser_widget->GetNativeView(), true);
333 } 332 }
334 333
335 if (source_tabstrip_) 334 if (source_tabstrip_)
336 GetModel(source_tabstrip_)->RemoveObserver(this); 335 GetModel(source_tabstrip_)->RemoveObserver(this);
337 336
338 MessageLoopForUI::current()->RemoveObserver(this); 337 MessageLoopForUI::current()->RemoveObserver(this);
339 } 338 }
340 339
341 void TabDragController2::Init( 340 void TabDragController2::Init(
342 TabStrip* source_tabstrip, 341 TabStrip* source_tabstrip,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // to the way they were. This is the most reliable way to do this since no 459 // to the way they were. This is the most reliable way to do this since no
461 // single view or window reliably receives events throughout all the various 460 // single view or window reliably receives events throughout all the various
462 // kinds of tab dragging. 461 // kinds of tab dragging.
463 if (ui::EventTypeFromNative(event) == ui::ET_KEY_PRESSED && 462 if (ui::EventTypeFromNative(event) == ui::ET_KEY_PRESSED &&
464 ui::KeyboardCodeFromNative(event) == ui::VKEY_ESCAPE) { 463 ui::KeyboardCodeFromNative(event) == ui::VKEY_ESCAPE) {
465 EndDrag(true); 464 EndDrag(true);
466 } 465 }
467 } 466 }
468 #endif 467 #endif
469 468
470 void TabDragController2::OnWidgetMoved() { 469 void TabDragController2::OnWidgetMove(views::Widget* widget) {
471 Drag(); 470 Drag();
472 } 471 }
473 472
474 void TabDragController2::TabStripEmpty() { 473 void TabDragController2::TabStripEmpty() {
475 GetModel(source_tabstrip_)->RemoveObserver(this); 474 GetModel(source_tabstrip_)->RemoveObserver(this);
476 // NULL out source_tabstrip_ so that we don't attempt to add back to in (in 475 // NULL out source_tabstrip_ so that we don't attempt to add back to in (in
477 // the case of a revert). 476 // the case of a revert).
478 source_tabstrip_ = NULL; 477 source_tabstrip_ = NULL;
479 } 478 }
480 479
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (tab_strip_changed) { 595 if (tab_strip_changed) {
597 if (!target_tabstrip) { 596 if (!target_tabstrip) {
598 DetachIntoNewBrowserAndRunMoveLoop(screen_point); 597 DetachIntoNewBrowserAndRunMoveLoop(screen_point);
599 return; 598 return;
600 } 599 }
601 if (is_dragging_window_) { 600 if (is_dragging_window_) {
602 #if defined(USE_ASH) 601 #if defined(USE_ASH)
603 // ReleaseMouseCapture() is going to result in calling back to us (because 602 // ReleaseMouseCapture() is going to result in calling back to us (because
604 // it results in a move). That'll cause all sorts of problems. Reset the 603 // it results in a move). That'll cause all sorts of problems. Reset the
605 // observer so we don't get notified and process the event. 604 // observer so we don't get notified and process the event.
606 move_loop_browser_view_->set_move_observer(NULL); 605 move_loop_browser_view_->GetWidget()->RemoveObserver(this);
Ben Goodger (Google) 2012/04/18 15:56:48 Now that the only usage of |move_loop_browser_view
msw 2012/04/18 20:02:48 Done.
607 move_loop_browser_view_ = NULL; 606 move_loop_browser_view_ = NULL;
608 #endif 607 #endif
609 BrowserView* browser_view = GetAttachedBrowserView(); 608 BrowserView* browser_view = GetAttachedBrowserView();
610 // Need to release the drag controller before starting the move loop as 609 // Need to release the drag controller before starting the move loop as
611 // it's going to trigger capture lost, which cancels drag. 610 // it's going to trigger capture lost, which cancels drag.
612 attached_tabstrip_->ReleaseDragController(); 611 attached_tabstrip_->ReleaseDragController();
613 target_tabstrip->OwnDragController(this); 612 target_tabstrip->OwnDragController(this);
614 // Disable animations so that we don't see a close animation on aero. 613 // Disable animations so that we don't see a close animation on aero.
615 browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(false); 614 browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(false);
616 browser_view->GetWidget()->ReleaseMouseCapture(); 615 browser_view->GetWidget()->ReleaseMouseCapture();
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 browser->window()->Show(); 976 browser->window()->Show();
978 browser->window()->Activate(); 977 browser->window()->Activate();
979 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( 978 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(
980 true); 979 true);
981 RunMoveLoop(); 980 RunMoveLoop();
982 } 981 }
983 982
984 void TabDragController2::RunMoveLoop() { 983 void TabDragController2::RunMoveLoop() {
985 move_loop_browser_view_ = GetAttachedBrowserView(); 984 move_loop_browser_view_ = GetAttachedBrowserView();
986 DCHECK(move_loop_browser_view_); 985 DCHECK(move_loop_browser_view_);
987 move_loop_browser_view_->set_move_observer(this); 986 move_loop_browser_view_->GetWidget()->AddObserver(this);
988 is_dragging_window_ = true; 987 is_dragging_window_ = true;
989 bool destroyed = false; 988 bool destroyed = false;
990 destroyed_ = &destroyed; 989 destroyed_ = &destroyed;
991 // Running the move loop release mouse capture on windows, which triggers 990 // Running the move loop release mouse capture on windows, which triggers
992 // destroying the drag loop. Release mouse capture ourself before this while 991 // destroying the drag loop. Release mouse capture ourself before this while
993 // the Dragcontroller isn't owned by the TabStrip. 992 // the Dragcontroller isn't owned by the TabStrip.
994 attached_tabstrip_->ReleaseDragController(); 993 attached_tabstrip_->ReleaseDragController();
995 attached_tabstrip_->GetWidget()->ReleaseMouseCapture(); 994 attached_tabstrip_->GetWidget()->ReleaseMouseCapture();
996 attached_tabstrip_->OwnDragController(this); 995 attached_tabstrip_->OwnDragController(this);
997 views::Widget::MoveLoopResult result = 996 views::Widget::MoveLoopResult result =
998 move_loop_browser_view_->GetWidget()->RunMoveLoop(); 997 move_loop_browser_view_->GetWidget()->RunMoveLoop();
999 content::NotificationService::current()->Notify( 998 content::NotificationService::current()->Notify(
1000 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, 999 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE,
1001 content::NotificationService::AllBrowserContextsAndSources(), 1000 content::NotificationService::AllBrowserContextsAndSources(),
1002 content::NotificationService::NoDetails()); 1001 content::NotificationService::NoDetails());
1003 1002
1004 if (destroyed) 1003 if (destroyed)
1005 return; 1004 return;
1006 destroyed_ = NULL; 1005 destroyed_ = NULL;
1007 // Under chromeos we immediately set the |move_loop_browser_view_| to NULL. 1006 // Under chromeos we immediately set the |move_loop_browser_view_| to NULL.
1008 if (move_loop_browser_view_) { 1007 if (move_loop_browser_view_) {
1009 move_loop_browser_view_->set_move_observer(NULL); 1008 move_loop_browser_view_->GetWidget()->RemoveObserver(this);
1010 move_loop_browser_view_ = NULL; 1009 move_loop_browser_view_ = NULL;
1011 } 1010 }
1012 is_dragging_window_ = false; 1011 is_dragging_window_ = false;
1013 waiting_for_run_loop_to_exit_ = false; 1012 waiting_for_run_loop_to_exit_ = false;
1014 if (end_run_loop_behavior_ == END_RUN_LOOP_CONTINUE_DRAGGING) { 1013 if (end_run_loop_behavior_ == END_RUN_LOOP_CONTINUE_DRAGGING) {
1015 end_run_loop_behavior_ = END_RUN_LOOP_STOP_DRAGGING; 1014 end_run_loop_behavior_ = END_RUN_LOOP_STOP_DRAGGING;
1016 if (tab_strip_to_attach_to_after_exit_) { 1015 if (tab_strip_to_attach_to_after_exit_) {
1017 Detach(); 1016 Detach();
1018 gfx::Point screen_point(GetCursorScreenPoint()); 1017 gfx::Point screen_point(GetCursorScreenPoint());
1019 Attach(tab_strip_to_attach_to_after_exit_, screen_point); 1018 Attach(tab_strip_to_attach_to_after_exit_, screen_point);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 browser->window()->SetBounds(new_bounds); 1432 browser->window()->SetBounds(new_bounds);
1434 return browser; 1433 return browser;
1435 } 1434 }
1436 1435
1437 void TabDragController2::SetTrackedByWorkspace(gfx::NativeWindow window, 1436 void TabDragController2::SetTrackedByWorkspace(gfx::NativeWindow window,
1438 bool value) { 1437 bool value) {
1439 #if defined(USE_ASH) 1438 #if defined(USE_ASH)
1440 ash::SetTrackedByWorkspace(window, value); 1439 ash::SetTrackedByWorkspace(window, value);
1441 #endif 1440 #endif
1442 } 1441 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller2.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698