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

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

Issue 80323002: Restores maximized browser before dragging a tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restores maximized browser before dragging a tab (no animations) Created 7 years 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 | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 #endif 203 #endif
204 } 204 }
205 205
206 void SetWindowPositionManaged(gfx::NativeWindow window, bool value) { 206 void SetWindowPositionManaged(gfx::NativeWindow window, bool value) {
207 #if defined(USE_ASH) 207 #if defined(USE_ASH)
208 ash::wm::GetWindowState(window)->set_window_position_managed(value); 208 ash::wm::GetWindowState(window)->set_window_position_managed(value);
209 #endif 209 #endif
210 } 210 }
211 211
212 // Returns true if |tab_strip| browser window is docked. 212 // Returns true if |tab_strip| browser window is docked.
213 bool IsDocked(const TabStrip* tab_strip) { 213 bool IsDockedOrSnapped(const TabStrip* tab_strip) {
214 #if defined(USE_ASH) 214 #if defined(USE_ASH)
215 DCHECK(tab_strip); 215 DCHECK(tab_strip);
216 return ash::wm::GetWindowState( 216 ash::wm::WindowState* window_state =
217 tab_strip->GetWidget()->GetNativeWindow())->IsDocked(); 217 ash::wm::GetWindowState(tab_strip->GetWidget()->GetNativeWindow());
218 return window_state->IsDocked() ||
219 window_state->window_show_type() == ash::wm::SHOW_TYPE_LEFT_SNAPPED ||
220 window_state->window_show_type() == ash::wm::SHOW_TYPE_RIGHT_SNAPPED;
218 #endif 221 #endif
219 return false; 222 return false;
220 } 223 }
221 224
222 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate 225 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate
223 // of |bounds| is adjusted by |vertical_adjustment|. 226 // of |bounds| is adjusted by |vertical_adjustment|.
224 bool DoesRectContainVerticalPointExpanded( 227 bool DoesRectContainVerticalPointExpanded(
225 const gfx::Rect& bounds, 228 const gfx::Rect& bounds,
226 int vertical_adjustment, 229 int vertical_adjustment,
227 int y) { 230 int y) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 { 542 {
540 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); 543 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr());
541 SaveFocus(); 544 SaveFocus();
542 if (!ref) 545 if (!ref)
543 return; 546 return;
544 } 547 }
545 started_drag_ = true; 548 started_drag_ = true;
546 Attach(source_tabstrip_, gfx::Point()); 549 Attach(source_tabstrip_, gfx::Point());
547 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == 550 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) ==
548 GetModel(source_tabstrip_)->count()) { 551 GetModel(source_tabstrip_)->count()) {
552 if (was_source_maximized_ || was_source_fullscreen_) {
553 // When all tabs in a maximized browser are dragged the browser gets
554 // restored during the drag and maximized back when the drag ends.
555 views::Widget* widget = GetAttachedBrowserWidget();
556 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs();
sky 2013/11/21 23:29:29 Does this do the right thing if you have lots of t
varkha 2013/11/22 02:57:16 Thanks for noticing this. I think I was missing a
557 OffsetX(GetAttachedDragPoint(point_in_screen).x(), &drag_bounds);
558 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source_tabstrip_,
559 point_in_screen,
560 &drag_bounds));
561 new_bounds.Offset(-widget->GetRestoredBounds().x() +
562 point_in_screen.x() -
563 mouse_offset_.x(), 0);
564 widget->SetVisibilityChangedAnimationsEnabled(false);
565 widget->Restore();
566 widget->SetBounds(new_bounds);
567 widget->SetVisibilityChangedAnimationsEnabled(true);
568 }
549 RunMoveLoop(GetWindowOffset(point_in_screen)); 569 RunMoveLoop(GetWindowOffset(point_in_screen));
550 return; 570 return;
551 } 571 }
552 } 572 }
553 573
554 ContinueDragging(point_in_screen); 574 ContinueDragging(point_in_screen);
555 } 575 }
556 576
557 void TabDragController::EndDrag(EndDragReason reason) { 577 void TabDragController::EndDrag(EndDragReason reason) {
558 TRACE_EVENT0("views", "TabDragController::EndDrag"); 578 TRACE_EVENT0("views", "TabDragController::EndDrag");
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 GetModel(source_tabstrip_)->InsertWebContentsAt( 1947 GetModel(source_tabstrip_)->InsertWebContentsAt(
1928 data->source_model_index, data->contents, 1948 data->source_model_index, data->contents,
1929 (data->pinned ? TabStripModel::ADD_PINNED : 0)); 1949 (data->pinned ? TabStripModel::ADD_PINNED : 0));
1930 } 1950 }
1931 } 1951 }
1932 1952
1933 void TabDragController::CompleteDrag() { 1953 void TabDragController::CompleteDrag() {
1934 DCHECK(started_drag_); 1954 DCHECK(started_drag_);
1935 1955
1936 if (attached_tabstrip_) { 1956 if (attached_tabstrip_) {
1937 if (is_dragging_new_browser_) { 1957 if (IsDockedOrSnapped(attached_tabstrip_)) {
1938 if (IsDocked(attached_tabstrip_)) { 1958 DCHECK_EQ(host_desktop_type_, chrome::HOST_DESKTOP_TYPE_ASH);
1939 DCHECK_EQ(host_desktop_type_, chrome::HOST_DESKTOP_TYPE_ASH); 1959 was_source_maximized_ = false;
1940 was_source_maximized_ = false; 1960 was_source_fullscreen_ = false;
1941 was_source_fullscreen_ = false; 1961 }
1942 } 1962 // If source window was maximized - maximize the new window as well.
1943 // If source window was maximized - maximize the new window as well. 1963 if (was_source_maximized_ || was_source_fullscreen_)
1944 if (was_source_maximized_) 1964 GetAttachedBrowserWidget()->Maximize();
1945 attached_tabstrip_->GetWidget()->Maximize();
1946 #if defined(USE_ASH) 1965 #if defined(USE_ASH)
1947 if (was_source_fullscreen_ && 1966 if (was_source_fullscreen_ &&
1948 host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) { 1967 host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) {
1949 // In fullscreen mode it is only possible to get here if the source 1968 // In fullscreen mode it is only possible to get here if the source
1950 // was in "immersive fullscreen" mode, so toggle it back on. 1969 // was in "immersive fullscreen" mode, so toggle it back on.
1951 ash::accelerators::ToggleFullscreen(); 1970 ash::accelerators::ToggleFullscreen();
1952 } 1971 }
1953 #endif 1972 #endif
1954 } else {
1955 // When dragging results in maximized or fullscreen browser window getting
1956 // docked, restore it.
1957 if ((was_source_fullscreen_ || was_source_maximized_) &&
1958 (IsDocked(attached_tabstrip_))) {
1959 DCHECK_EQ(host_desktop_type_, chrome::HOST_DESKTOP_TYPE_ASH);
1960 attached_tabstrip_->GetWidget()->Restore();
1961 }
1962 }
1963 attached_tabstrip_->StoppedDraggingTabs( 1973 attached_tabstrip_->StoppedDraggingTabs(
1964 GetTabsMatchingDraggedContents(attached_tabstrip_), 1974 GetTabsMatchingDraggedContents(attached_tabstrip_),
1965 initial_tab_positions_, 1975 initial_tab_positions_,
1966 move_behavior_ == MOVE_VISIBILE_TABS, 1976 move_behavior_ == MOVE_VISIBILE_TABS,
1967 true); 1977 true);
1968 } else { 1978 } else {
1969 if (dock_info_.type() != DockInfo::NONE) { 1979 if (dock_info_.type() != DockInfo::NONE) {
1970 switch (dock_info_.type()) { 1980 switch (dock_info_.type()) {
1971 case DockInfo::LEFT_OF_WINDOW: 1981 case DockInfo::LEFT_OF_WINDOW:
1972 content::RecordAction(UserMetricsAction("DockingWindow_Left")); 1982 content::RecordAction(UserMetricsAction("DockingWindow_Left"));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 bool TabDragController::AreTabsConsecutive() { 2251 bool TabDragController::AreTabsConsecutive() {
2242 for (size_t i = 1; i < drag_data_.size(); ++i) { 2252 for (size_t i = 1; i < drag_data_.size(); ++i) {
2243 if (drag_data_[i - 1].source_model_index + 1 != 2253 if (drag_data_[i - 1].source_model_index + 1 !=
2244 drag_data_[i].source_model_index) { 2254 drag_data_[i].source_model_index) {
2245 return false; 2255 return false;
2246 } 2256 }
2247 } 2257 }
2248 return true; 2258 return true;
2249 } 2259 }
2250 2260
2251 Browser* TabDragController::CreateBrowserForDrag( 2261 gfx::Rect TabDragController::CalculateDraggedBrowserBounds(
2252 TabStrip* source, 2262 TabStrip* source,
2253 const gfx::Point& point_in_screen, 2263 const gfx::Point& point_in_screen,
2254 gfx::Vector2d* drag_offset,
2255 std::vector<gfx::Rect>* drag_bounds) { 2264 std::vector<gfx::Rect>* drag_bounds) {
2256 gfx::Point center(0, source->height() / 2); 2265 gfx::Point center(0, source->height() / 2);
2257 views::View::ConvertPointToWidget(source, &center); 2266 views::View::ConvertPointToWidget(source, &center);
2258 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds()); 2267 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds());
2259 if (source->GetWidget()->IsMaximized()) { 2268 if (source->GetWidget()->IsMaximized()) {
2260 // If the restore bounds is really small, we don't want to honor it 2269 // If the restore bounds is really small, we don't want to honor it
2261 // (dragging a really small window looks wrong), instead make sure the new 2270 // (dragging a really small window looks wrong), instead make sure the new
2262 // window is at least 50% the size of the old. 2271 // window is at least 50% the size of the old.
2263 const gfx::Size max_size( 2272 const gfx::Size max_size(
2264 source->GetWidget()->GetWindowBoundsInScreen().size()); 2273 source->GetWidget()->GetWindowBoundsInScreen().size());
(...skipping 18 matching lines...) Expand all
2283 } 2292 }
2284 default: 2293 default:
2285 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. 2294 break; // Nothing to do for DETACH_ABOVE_OR_BELOW.
2286 } 2295 }
2287 2296
2288 // To account for the extra vertical on restored windows that is absent on 2297 // To account for the extra vertical on restored windows that is absent on
2289 // maximized windows, add an additional vertical offset extracted from the tab 2298 // maximized windows, add an additional vertical offset extracted from the tab
2290 // strip. 2299 // strip.
2291 if (source->GetWidget()->IsMaximized()) 2300 if (source->GetWidget()->IsMaximized())
2292 new_bounds.Offset(0, -source->button_v_offset()); 2301 new_bounds.Offset(0, -source->button_v_offset());
2302 return new_bounds;
2303 }
2293 2304
2305 Browser* TabDragController::CreateBrowserForDrag(
2306 TabStrip* source,
2307 const gfx::Point& point_in_screen,
2308 gfx::Vector2d* drag_offset,
2309 std::vector<gfx::Rect>* drag_bounds) {
2310 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source,
2311 point_in_screen,
2312 drag_bounds));
2294 *drag_offset = point_in_screen - new_bounds.origin(); 2313 *drag_offset = point_in_screen - new_bounds.origin();
2295 2314
2296 Profile* profile = 2315 Profile* profile =
2297 Profile::FromBrowserContext(drag_data_[0].contents->GetBrowserContext()); 2316 Profile::FromBrowserContext(drag_data_[0].contents->GetBrowserContext());
2298 Browser::CreateParams create_params(Browser::TYPE_TABBED, 2317 Browser::CreateParams create_params(Browser::TYPE_TABBED,
2299 profile, 2318 profile,
2300 host_desktop_type_); 2319 host_desktop_type_);
2301 create_params.initial_bounds = new_bounds; 2320 create_params.initial_bounds = new_bounds;
2302 Browser* browser = new Browser(create_params); 2321 Browser* browser = new Browser(create_params);
2303 is_dragging_new_browser_ = true; 2322 is_dragging_new_browser_ = true;
(...skipping 29 matching lines...) Expand all
2333 gfx::Vector2d TabDragController::GetWindowOffset( 2352 gfx::Vector2d TabDragController::GetWindowOffset(
2334 const gfx::Point& point_in_screen) { 2353 const gfx::Point& point_in_screen) {
2335 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? 2354 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ?
2336 attached_tabstrip_ : source_tabstrip_; 2355 attached_tabstrip_ : source_tabstrip_;
2337 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); 2356 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView();
2338 2357
2339 gfx::Point point = point_in_screen; 2358 gfx::Point point = point_in_screen;
2340 views::View::ConvertPointFromScreen(toplevel_view, &point); 2359 views::View::ConvertPointFromScreen(toplevel_view, &point);
2341 return point.OffsetFromOrigin(); 2360 return point.OffsetFromOrigin();
2342 } 2361 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698