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

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

Issue 2640433004: ChromeOS MD: Fix cannot drag tab onto immersive fullscreen window (Closed)
Patch Set: clean the code based on ps2's comments Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.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 "chrome/browser/ui/views/tabs/tab_drag_controller.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 gfx::NativeWindow GetModalTransient(gfx::NativeWindow window) { 104 gfx::NativeWindow GetModalTransient(gfx::NativeWindow window) {
105 return wm::GetModalTransient(window); 105 return wm::GetModalTransient(window);
106 } 106 }
107 #else 107 #else
108 gfx::NativeWindow GetModalTransient(gfx::NativeWindow window) { 108 gfx::NativeWindow GetModalTransient(gfx::NativeWindow window) {
109 NOTIMPLEMENTED(); 109 NOTIMPLEMENTED();
110 return NULL; 110 return NULL;
111 } 111 }
112 #endif 112 #endif
113 113
114 // Get tabstrip bounds from non-client view coordinates where tabstrip should be
sky 2017/01/18 16:40:46 I think you mean, "Returns the bounds of the tabst
Qiang(Joe) Xu 2017/01/20 17:36:25 changed to GetBoundsForTabStripInBrowserView, so c
115 // laid when revealed, then convert to screen coordinates. Return false if the
116 // corresponding browser view doesn't exist.
117 bool GetBoundsForTabStripInScreen(TabStrip* tabstrip, gfx::Rect* rect) {
118 if (!tabstrip)
119 return false;
sky 2017/01/18 16:40:46 I think callers should check for this case.
Qiang(Joe) Xu 2017/01/20 17:36:25 caller will make sure it
120 gfx::NativeWindow window = tabstrip->GetWidget()->GetNativeWindow();
121 if (!window)
sky 2017/01/18 16:40:46 Can this case really happen?
Qiang(Joe) Xu 2017/01/20 17:36:25 seems cannot happen. remove it.
122 return false;
123 BrowserView* browser_view =
124 BrowserView::GetBrowserViewForNativeWindow(window);
125 if (!browser_view)
sky 2017/01/18 16:40:46 Same comment here. Can this case really happen?
Qiang(Joe) Xu 2017/01/20 17:36:25 Done.
126 return false;
127 *rect = browser_view->frame()->GetBoundsForTabStrip(tabstrip);
sky 2017/01/18 16:40:46 Why do you need to use GetBoundsForTabStrip rather
Qiang(Joe) Xu 2017/01/20 17:36:25 the actual bounds will return (0, 0, 0x0) for this
128 aura::Window::ConvertRectToTarget(window, window->GetRootWindow(), rect);
129 return true;
130 }
131
114 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate 132 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate
115 // of |bounds| is adjusted by |vertical_adjustment|. 133 // of |bounds| is adjusted by |vertical_adjustment|.
116 bool DoesRectContainVerticalPointExpanded( 134 bool DoesRectContainVerticalPointExpanded(
117 const gfx::Rect& bounds, 135 const gfx::Rect& bounds,
118 int vertical_adjustment, 136 int vertical_adjustment,
119 int y) { 137 int y) {
120 int upper_threshold = bounds.bottom() + vertical_adjustment; 138 int upper_threshold = bounds.bottom() + vertical_adjustment;
121 int lower_threshold = bounds.y() - vertical_adjustment; 139 int lower_threshold = bounds.y() - vertical_adjustment;
122 return y >= lower_threshold && y <= upper_threshold; 140 return y >= lower_threshold && y <= upper_threshold;
123 } 141 }
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 TabStrip* target_tabstrip, 580 TabStrip* target_tabstrip,
563 const gfx::Point& point_in_screen) { 581 const gfx::Point& point_in_screen) {
564 TRACE_EVENT1("views", "TabDragController::DragBrowserToNewTabStrip", 582 TRACE_EVENT1("views", "TabDragController::DragBrowserToNewTabStrip",
565 "point_in_screen", point_in_screen.ToString()); 583 "point_in_screen", point_in_screen.ToString());
566 584
567 if (!target_tabstrip) { 585 if (!target_tabstrip) {
568 DetachIntoNewBrowserAndRunMoveLoop(point_in_screen); 586 DetachIntoNewBrowserAndRunMoveLoop(point_in_screen);
569 return DRAG_BROWSER_RESULT_STOP; 587 return DRAG_BROWSER_RESULT_STOP;
570 } 588 }
571 589
590 // If tabstrip is invisible, it is not eligible to determine the tab insertion
591 // position, so show the tabstrip here.
592 gfx::Rect tabstrip_bounds;
593 if (!target_tabstrip->visible() &&
594 GetBoundsForTabStripInScreen(target_tabstrip, &tabstrip_bounds)) {
595 target_tabstrip->SetVisible(true);
596 target_tabstrip->SetBoundsRect(tabstrip_bounds);
597 }
598
572 #if defined(USE_AURA) 599 #if defined(USE_AURA)
573 // Only Aura windows are gesture consumers. 600 // Only Aura windows are gesture consumers.
574 ui::GestureRecognizer::Get()->TransferEventsTo( 601 ui::GestureRecognizer::Get()->TransferEventsTo(
575 GetAttachedBrowserWidget()->GetNativeView(), 602 GetAttachedBrowserWidget()->GetNativeView(),
576 target_tabstrip->GetWidget()->GetNativeView(), 603 target_tabstrip->GetWidget()->GetNativeView(),
577 ui::GestureRecognizer::ShouldCancelTouches::DontCancel); 604 ui::GestureRecognizer::ShouldCancelTouches::DontCancel);
578 #endif 605 #endif
579 606
580 if (is_dragging_window_) { 607 if (is_dragging_window_) {
581 // ReleaseCapture() is going to result in calling back to us (because it 608 // ReleaseCapture() is going to result in calling back to us (because it
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 attached_tabstrip_ ? attached_tabstrip_ : source_tabstrip_; 876 attached_tabstrip_ ? attached_tabstrip_ : source_tabstrip_;
850 DCHECK(tab_strip); 877 DCHECK(tab_strip);
851 878
852 return other_tabstrip->controller()->IsCompatibleWith(tab_strip) ? 879 return other_tabstrip->controller()->IsCompatibleWith(tab_strip) ?
853 other_tabstrip : NULL; 880 other_tabstrip : NULL;
854 } 881 }
855 882
856 bool TabDragController::DoesTabStripContain( 883 bool TabDragController::DoesTabStripContain(
857 TabStrip* tabstrip, 884 TabStrip* tabstrip,
858 const gfx::Point& point_in_screen) const { 885 const gfx::Point& point_in_screen) const {
859 // Make sure the specified screen point is actually within the bounds of the 886 // Make sure the specified screen point is within the bounds of the specified
860 // specified tabstrip... 887 // tabstrip where it should be laid when revealed.
861 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip); 888 gfx::Rect tabstrip_bounds;
889 DCHECK(GetBoundsForTabStripInScreen(tabstrip, &tabstrip_bounds));
890
862 return point_in_screen.x() < tabstrip_bounds.right() && 891 return point_in_screen.x() < tabstrip_bounds.right() &&
863 point_in_screen.x() >= tabstrip_bounds.x() && 892 point_in_screen.x() >= tabstrip_bounds.x() &&
864 DoesRectContainVerticalPointExpanded(tabstrip_bounds, 893 DoesRectContainVerticalPointExpanded(
865 kVerticalDetachMagnetism, 894 tabstrip_bounds, kVerticalDetachMagnetism, point_in_screen.y());
866 point_in_screen.y());
867 } 895 }
868 896
869 void TabDragController::Attach(TabStrip* attached_tabstrip, 897 void TabDragController::Attach(TabStrip* attached_tabstrip,
870 const gfx::Point& point_in_screen) { 898 const gfx::Point& point_in_screen) {
871 TRACE_EVENT1("views", "TabDragController::Attach", 899 TRACE_EVENT1("views", "TabDragController::Attach",
872 "point_in_screen", point_in_screen.ToString()); 900 "point_in_screen", point_in_screen.ToString());
873 901
874 DCHECK(!attached_tabstrip_); // We should already have detached by the time 902 DCHECK(!attached_tabstrip_); // We should already have detached by the time
875 // we get here. 903 // we get here.
876 904
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 // TODO(pkotwicz): Fix this properly (crbug.com/358482) 1823 // TODO(pkotwicz): Fix this properly (crbug.com/358482)
1796 for (auto* browser : *BrowserList::GetInstance()) { 1824 for (auto* browser : *BrowserList::GetInstance()) {
1797 if (browser->tab_strip_model()->empty()) 1825 if (browser->tab_strip_model()->empty())
1798 exclude.insert(browser->window()->GetNativeWindow()); 1826 exclude.insert(browser->window()->GetNativeWindow());
1799 } 1827 }
1800 #endif 1828 #endif
1801 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); 1829 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr());
1802 *window = window_finder_->GetLocalProcessWindowAtPoint(screen_point, exclude); 1830 *window = window_finder_->GetLocalProcessWindowAtPoint(screen_point, exclude);
1803 return ref ? Liveness::ALIVE : Liveness::DELETED; 1831 return ref ? Liveness::ALIVE : Liveness::DELETED;
1804 } 1832 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698