| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 // static | 358 // static |
| 359 const int TabDragController::kVerticalDetachMagnetism = 15; | 359 const int TabDragController::kVerticalDetachMagnetism = 15; |
| 360 | 360 |
| 361 TabDragController::TabDragController() | 361 TabDragController::TabDragController() |
| 362 : detach_into_browser_(ShouldDetachIntoNewBrowser()), | 362 : detach_into_browser_(ShouldDetachIntoNewBrowser()), |
| 363 source_tabstrip_(NULL), | 363 source_tabstrip_(NULL), |
| 364 attached_tabstrip_(NULL), | 364 attached_tabstrip_(NULL), |
| 365 screen_(NULL), | 365 screen_(NULL), |
| 366 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 366 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| 367 source_tab_offset_(0), | |
| 368 offset_to_width_ratio_(0), | 367 offset_to_width_ratio_(0), |
| 369 old_focused_view_(NULL), | 368 old_focused_view_(NULL), |
| 370 last_move_screen_loc_(0), | 369 last_move_screen_loc_(0), |
| 371 started_drag_(false), | 370 started_drag_(false), |
| 372 active_(true), | 371 active_(true), |
| 373 source_tab_index_(std::numeric_limits<size_t>::max()), | 372 source_tab_index_(std::numeric_limits<size_t>::max()), |
| 374 initial_move_(true), | 373 initial_move_(true), |
| 375 detach_behavior_(DETACHABLE), | 374 detach_behavior_(DETACHABLE), |
| 376 move_behavior_(REORDER), | 375 move_behavior_(REORDER), |
| 377 mouse_move_direction_(0), | 376 mouse_move_direction_(0), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 const ui::ListSelectionModel& initial_selection_model, | 423 const ui::ListSelectionModel& initial_selection_model, |
| 425 DetachBehavior detach_behavior, | 424 DetachBehavior detach_behavior, |
| 426 MoveBehavior move_behavior) { | 425 MoveBehavior move_behavior) { |
| 427 DCHECK(!tabs.empty()); | 426 DCHECK(!tabs.empty()); |
| 428 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end()); | 427 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end()); |
| 429 source_tabstrip_ = source_tabstrip; | 428 source_tabstrip_ = source_tabstrip; |
| 430 screen_ = gfx::Screen::GetScreenFor( | 429 screen_ = gfx::Screen::GetScreenFor( |
| 431 source_tabstrip->GetWidget()->GetNativeView()); | 430 source_tabstrip->GetWidget()->GetNativeView()); |
| 432 host_desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 431 host_desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
| 433 source_tabstrip->GetWidget()->GetNativeView()); | 432 source_tabstrip->GetWidget()->GetNativeView()); |
| 434 source_tab_offset_ = source_tab_offset; | |
| 435 start_point_in_screen_ = gfx::Point(source_tab_offset, mouse_offset.y()); | 433 start_point_in_screen_ = gfx::Point(source_tab_offset, mouse_offset.y()); |
| 436 views::View::ConvertPointToScreen(source_tab, &start_point_in_screen_); | 434 views::View::ConvertPointToScreen(source_tab, &start_point_in_screen_); |
| 437 mouse_offset_ = mouse_offset; | 435 mouse_offset_ = mouse_offset; |
| 438 detach_behavior_ = detach_behavior; | 436 detach_behavior_ = detach_behavior; |
| 439 move_behavior_ = move_behavior; | 437 move_behavior_ = move_behavior; |
| 440 last_point_in_screen_ = start_point_in_screen_; | 438 last_point_in_screen_ = start_point_in_screen_; |
| 441 last_move_screen_loc_ = start_point_in_screen_.x(); | 439 last_move_screen_loc_ = start_point_in_screen_.x(); |
| 442 initial_tab_positions_ = source_tabstrip->GetTabXCoordinates(); | 440 initial_tab_positions_ = source_tabstrip->GetTabXCoordinates(); |
| 443 if (detach_into_browser_) | 441 if (detach_into_browser_) |
| 444 GetModel(source_tabstrip_)->AddObserver(this); | 442 GetModel(source_tabstrip_)->AddObserver(this); |
| 445 | 443 |
| 446 drag_data_.resize(tabs.size()); | 444 drag_data_.resize(tabs.size()); |
| 447 for (size_t i = 0; i < tabs.size(); ++i) | 445 for (size_t i = 0; i < tabs.size(); ++i) |
| 448 InitTabDragData(tabs[i], &(drag_data_[i])); | 446 InitTabDragData(tabs[i], &(drag_data_[i])); |
| 449 source_tab_index_ = | 447 source_tab_index_ = |
| 450 std::find(tabs.begin(), tabs.end(), source_tab) - tabs.begin(); | 448 std::find(tabs.begin(), tabs.end(), source_tab) - tabs.begin(); |
| 451 | 449 |
| 452 // Listen for Esc key presses. | 450 // Listen for Esc key presses. |
| 453 MessageLoopForUI::current()->AddObserver(this); | 451 MessageLoopForUI::current()->AddObserver(this); |
| 454 | 452 |
| 455 if (source_tab->width() > 0) { | 453 if (source_tab->width() > 0) { |
| 456 offset_to_width_ratio_ = static_cast<float>(source_tab_offset_) / | 454 offset_to_width_ratio_ = static_cast<float>( |
| 455 source_tab->GetMirroredXInView(source_tab_offset)) / |
| 457 static_cast<float>(source_tab->width()); | 456 static_cast<float>(source_tab->width()); |
| 458 } | 457 } |
| 459 InitWindowCreatePoint(); | 458 InitWindowCreatePoint(); |
| 460 initial_selection_model_.Copy(initial_selection_model); | 459 initial_selection_model_.Copy(initial_selection_model); |
| 461 } | 460 } |
| 462 | 461 |
| 463 // static | 462 // static |
| 464 bool TabDragController::IsAttachedTo(TabStrip* tab_strip) { | 463 bool TabDragController::IsAttachedTo(TabStrip* tab_strip) { |
| 465 return (instance_ && instance_->active() && | 464 return (instance_ && instance_->active() && |
| 466 instance_->attached_tabstrip() == tab_strip); | 465 instance_->attached_tabstrip() == tab_strip); |
| (...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 gfx::Vector2d TabDragController::GetWindowOffset( | 2041 gfx::Vector2d TabDragController::GetWindowOffset( |
| 2043 const gfx::Point& point_in_screen) { | 2042 const gfx::Point& point_in_screen) { |
| 2044 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 2043 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
| 2045 attached_tabstrip_ : source_tabstrip_; | 2044 attached_tabstrip_ : source_tabstrip_; |
| 2046 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2045 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
| 2047 | 2046 |
| 2048 gfx::Point point = point_in_screen; | 2047 gfx::Point point = point_in_screen; |
| 2049 views::View::ConvertPointFromScreen(toplevel_view, &point); | 2048 views::View::ConvertPointFromScreen(toplevel_view, &point); |
| 2050 return point.OffsetFromOrigin(); | 2049 return point.OffsetFromOrigin(); |
| 2051 } | 2050 } |
| OLD | NEW |