OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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_fullscreen_ || was_source_maximized_) { | |
553 views::Widget* widget = GetAttachedBrowserWidget(); | |
554 WindowPositionManagedUpdater updater; | |
555 widget->AddObserver(&updater); | |
556 widget->SetVisibilityChangedAnimationsEnabled(false); | |
557 widget->Hide(); | |
varkha
2013/11/21 16:59:35
I need to see if this breaks non-metro Windows.
| |
558 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(); | |
559 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source_tabstrip_, | |
560 point_in_screen, | |
561 &drag_bounds)); | |
562 widget->Restore(); | |
563 widget->SetBounds(new_bounds); | |
564 widget->Show(); | |
565 widget->RemoveObserver(&updater); | |
566 widget->SetVisibilityChangedAnimationsEnabled(true); | |
567 | |
568 // Mouse handler was lost when the browser widget was hidden. | |
569 // Reestablish the event handler. | |
570 static_cast<views::internal::RootView*>( | |
571 widget->GetRootView())->SetMouseHandler(attached_tabstrip_); | |
572 } | |
549 RunMoveLoop(GetWindowOffset(point_in_screen)); | 573 RunMoveLoop(GetWindowOffset(point_in_screen)); |
550 return; | 574 return; |
551 } | 575 } |
552 } | 576 } |
553 | 577 |
554 ContinueDragging(point_in_screen); | 578 ContinueDragging(point_in_screen); |
555 } | 579 } |
556 | 580 |
557 void TabDragController::EndDrag(EndDragReason reason) { | 581 void TabDragController::EndDrag(EndDragReason reason) { |
558 TRACE_EVENT0("views", "TabDragController::EndDrag"); | 582 TRACE_EVENT0("views", "TabDragController::EndDrag"); |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 GetModel(source_tabstrip_)->InsertWebContentsAt( | 1951 GetModel(source_tabstrip_)->InsertWebContentsAt( |
1928 data->source_model_index, data->contents, | 1952 data->source_model_index, data->contents, |
1929 (data->pinned ? TabStripModel::ADD_PINNED : 0)); | 1953 (data->pinned ? TabStripModel::ADD_PINNED : 0)); |
1930 } | 1954 } |
1931 } | 1955 } |
1932 | 1956 |
1933 void TabDragController::CompleteDrag() { | 1957 void TabDragController::CompleteDrag() { |
1934 DCHECK(started_drag_); | 1958 DCHECK(started_drag_); |
1935 | 1959 |
1936 if (attached_tabstrip_) { | 1960 if (attached_tabstrip_) { |
1937 if (is_dragging_new_browser_) { | 1961 if (IsDockedOrSnapped(attached_tabstrip_)) { |
1938 if (IsDocked(attached_tabstrip_)) { | 1962 DCHECK_EQ(host_desktop_type_, chrome::HOST_DESKTOP_TYPE_ASH); |
1939 DCHECK_EQ(host_desktop_type_, chrome::HOST_DESKTOP_TYPE_ASH); | 1963 was_source_maximized_ = false; |
1940 was_source_maximized_ = false; | 1964 was_source_fullscreen_ = false; |
1941 was_source_fullscreen_ = false; | 1965 } |
1942 } | 1966 // If source window was maximized - maximize the new window as well. |
1943 // If source window was maximized - maximize the new window as well. | 1967 if (was_source_maximized_ || was_source_fullscreen_) |
1944 if (was_source_maximized_) | 1968 GetAttachedBrowserWidget()->Maximize(); |
1945 attached_tabstrip_->GetWidget()->Maximize(); | |
1946 #if defined(USE_ASH) | 1969 #if defined(USE_ASH) |
1947 if (was_source_fullscreen_ && | 1970 if (was_source_fullscreen_ && |
1948 host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) { | 1971 host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) { |
1949 // In fullscreen mode it is only possible to get here if the source | 1972 // In fullscreen mode it is only possible to get here if the source |
1950 // was in "immersive fullscreen" mode, so toggle it back on. | 1973 // was in "immersive fullscreen" mode, so toggle it back on. |
1951 ash::accelerators::ToggleFullscreen(); | 1974 ash::accelerators::ToggleFullscreen(); |
1952 } | 1975 } |
1953 #endif | 1976 #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( | 1977 attached_tabstrip_->StoppedDraggingTabs( |
1964 GetTabsMatchingDraggedContents(attached_tabstrip_), | 1978 GetTabsMatchingDraggedContents(attached_tabstrip_), |
1965 initial_tab_positions_, | 1979 initial_tab_positions_, |
1966 move_behavior_ == MOVE_VISIBILE_TABS, | 1980 move_behavior_ == MOVE_VISIBILE_TABS, |
1967 true); | 1981 true); |
1968 } else { | 1982 } else { |
1969 if (dock_info_.type() != DockInfo::NONE) { | 1983 if (dock_info_.type() != DockInfo::NONE) { |
1970 switch (dock_info_.type()) { | 1984 switch (dock_info_.type()) { |
1971 case DockInfo::LEFT_OF_WINDOW: | 1985 case DockInfo::LEFT_OF_WINDOW: |
1972 content::RecordAction(UserMetricsAction("DockingWindow_Left")); | 1986 content::RecordAction(UserMetricsAction("DockingWindow_Left")); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2241 bool TabDragController::AreTabsConsecutive() { | 2255 bool TabDragController::AreTabsConsecutive() { |
2242 for (size_t i = 1; i < drag_data_.size(); ++i) { | 2256 for (size_t i = 1; i < drag_data_.size(); ++i) { |
2243 if (drag_data_[i - 1].source_model_index + 1 != | 2257 if (drag_data_[i - 1].source_model_index + 1 != |
2244 drag_data_[i].source_model_index) { | 2258 drag_data_[i].source_model_index) { |
2245 return false; | 2259 return false; |
2246 } | 2260 } |
2247 } | 2261 } |
2248 return true; | 2262 return true; |
2249 } | 2263 } |
2250 | 2264 |
2251 Browser* TabDragController::CreateBrowserForDrag( | 2265 gfx::Rect TabDragController::CalculateDraggedBrowserBounds( |
2252 TabStrip* source, | 2266 TabStrip* source, |
2253 const gfx::Point& point_in_screen, | 2267 const gfx::Point& point_in_screen, |
2254 gfx::Vector2d* drag_offset, | |
2255 std::vector<gfx::Rect>* drag_bounds) { | 2268 std::vector<gfx::Rect>* drag_bounds) { |
2256 gfx::Point center(0, source->height() / 2); | 2269 gfx::Point center(0, source->height() / 2); |
2257 views::View::ConvertPointToWidget(source, ¢er); | 2270 views::View::ConvertPointToWidget(source, ¢er); |
2258 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds()); | 2271 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds()); |
2259 if (source->GetWidget()->IsMaximized()) { | 2272 if (source->GetWidget()->IsMaximized()) { |
2260 // If the restore bounds is really small, we don't want to honor it | 2273 // 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 | 2274 // (dragging a really small window looks wrong), instead make sure the new |
2262 // window is at least 50% the size of the old. | 2275 // window is at least 50% the size of the old. |
2263 const gfx::Size max_size( | 2276 const gfx::Size max_size( |
2264 source->GetWidget()->GetWindowBoundsInScreen().size()); | 2277 source->GetWidget()->GetWindowBoundsInScreen().size()); |
2265 new_bounds.set_width( | 2278 new_bounds.set_width( |
2266 std::max(max_size.width() / 2, new_bounds.width())); | 2279 std::max(max_size.width() / 2, new_bounds.width())); |
2267 new_bounds.set_height( | 2280 new_bounds.set_height( |
2268 std::max(max_size.height() / 2, new_bounds.width())); | 2281 std::max(max_size.height() / 2, new_bounds.width())); |
2269 } | 2282 } |
2270 new_bounds.set_y(point_in_screen.y() - center.y()); | 2283 new_bounds.set_y(point_in_screen.y() - center.y()); |
2271 switch (GetDetachPosition(point_in_screen)) { | 2284 switch (GetDetachPosition(point_in_screen)) { |
2272 case DETACH_BEFORE: | |
2273 new_bounds.set_x(point_in_screen.x() - center.x()); | |
2274 new_bounds.Offset(-mouse_offset_.x(), 0); | |
2275 break; | |
2276 case DETACH_AFTER: { | 2285 case DETACH_AFTER: { |
2277 gfx::Point right_edge(source->width(), 0); | 2286 gfx::Point right_edge(source->width(), 0); |
2278 views::View::ConvertPointToWidget(source, &right_edge); | 2287 views::View::ConvertPointToWidget(source, &right_edge); |
2279 new_bounds.set_x(point_in_screen.x() - right_edge.x()); | 2288 new_bounds.set_x(point_in_screen.x() - right_edge.x()); |
2280 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); | 2289 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); |
2281 OffsetX(-(*drag_bounds)[0].x(), drag_bounds); | 2290 OffsetX(-(*drag_bounds)[0].x(), drag_bounds); |
2282 break; | 2291 break; |
2283 } | 2292 } |
2293 case DETACH_BEFORE: | |
sky
2013/11/21 16:43:07
Why are you changing this?
varkha
2013/11/21 16:59:35
It does not seem to break the existing case and ma
sky
2013/11/21 17:15:35
I wanted dragging up/down to appear to tear a new
varkha
2013/11/21 17:23:10
That is what it seems to be doing (still in the ol
varkha
2013/11/21 20:34:48
I understand now - the case I broke was dragging t
| |
2284 default: | 2294 default: |
2285 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. | 2295 new_bounds.set_x(point_in_screen.x() - center.x()); |
2296 new_bounds.Offset(-mouse_offset_.x(), 0); | |
2297 break; | |
2286 } | 2298 } |
2287 | 2299 |
2288 // To account for the extra vertical on restored windows that is absent on | 2300 // 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 | 2301 // maximized windows, add an additional vertical offset extracted from the tab |
2290 // strip. | 2302 // strip. |
2291 if (source->GetWidget()->IsMaximized()) | 2303 if (source->GetWidget()->IsMaximized()) |
2292 new_bounds.Offset(0, -source->button_v_offset()); | 2304 new_bounds.Offset(0, -source->button_v_offset()); |
2305 return new_bounds; | |
2306 } | |
2293 | 2307 |
2308 Browser* TabDragController::CreateBrowserForDrag( | |
2309 TabStrip* source, | |
2310 const gfx::Point& point_in_screen, | |
2311 gfx::Vector2d* drag_offset, | |
2312 std::vector<gfx::Rect>* drag_bounds) { | |
2313 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source, | |
2314 point_in_screen, | |
2315 drag_bounds)); | |
2294 *drag_offset = point_in_screen - new_bounds.origin(); | 2316 *drag_offset = point_in_screen - new_bounds.origin(); |
2295 | 2317 |
2296 Profile* profile = | 2318 Profile* profile = |
2297 Profile::FromBrowserContext(drag_data_[0].contents->GetBrowserContext()); | 2319 Profile::FromBrowserContext(drag_data_[0].contents->GetBrowserContext()); |
2298 Browser::CreateParams create_params(Browser::TYPE_TABBED, | 2320 Browser::CreateParams create_params(Browser::TYPE_TABBED, |
2299 profile, | 2321 profile, |
2300 host_desktop_type_); | 2322 host_desktop_type_); |
2301 create_params.initial_bounds = new_bounds; | 2323 create_params.initial_bounds = new_bounds; |
2302 Browser* browser = new Browser(create_params); | 2324 Browser* browser = new Browser(create_params); |
2303 is_dragging_new_browser_ = true; | 2325 is_dragging_new_browser_ = true; |
(...skipping 29 matching lines...) Expand all Loading... | |
2333 gfx::Vector2d TabDragController::GetWindowOffset( | 2355 gfx::Vector2d TabDragController::GetWindowOffset( |
2334 const gfx::Point& point_in_screen) { | 2356 const gfx::Point& point_in_screen) { |
2335 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 2357 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
2336 attached_tabstrip_ : source_tabstrip_; | 2358 attached_tabstrip_ : source_tabstrip_; |
2337 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2359 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
2338 | 2360 |
2339 gfx::Point point = point_in_screen; | 2361 gfx::Point point = point_in_screen; |
2340 views::View::ConvertPointFromScreen(toplevel_view, &point); | 2362 views::View::ConvertPointFromScreen(toplevel_view, &point); |
2341 return point.OffsetFromOrigin(); | 2363 return point.OffsetFromOrigin(); |
2342 } | 2364 } |
OLD | NEW |