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 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1133 |
1134 if (!detach_into_browser_) { | 1134 if (!detach_into_browser_) { |
1135 // Remove ourselves as the delegate now that the dragged WebContents is | 1135 // Remove ourselves as the delegate now that the dragged WebContents is |
1136 // being inserted back into a Browser. | 1136 // being inserted back into a Browser. |
1137 for (size_t i = 0; i < drag_data_.size(); ++i) { | 1137 for (size_t i = 0; i < drag_data_.size(); ++i) { |
1138 drag_data_[i].contents->SetDelegate(NULL); | 1138 drag_data_[i].contents->SetDelegate(NULL); |
1139 drag_data_[i].original_delegate = NULL; | 1139 drag_data_[i].original_delegate = NULL; |
1140 } | 1140 } |
1141 | 1141 |
1142 // Return the WebContents to normalcy. | 1142 // Return the WebContents to normalcy. |
1143 source_dragged_contents()->SetCapturingContents(false); | 1143 source_dragged_contents()->DecrementCapturerCount(); |
1144 } | 1144 } |
1145 | 1145 |
1146 // Inserting counts as a move. We don't want the tabs to jitter when the | 1146 // Inserting counts as a move. We don't want the tabs to jitter when the |
1147 // user moves the tab immediately after attaching it. | 1147 // user moves the tab immediately after attaching it. |
1148 last_move_screen_loc_ = point_in_screen.x(); | 1148 last_move_screen_loc_ = point_in_screen.x(); |
1149 | 1149 |
1150 // Figure out where to insert the tab based on the bounds of the dragged | 1150 // Figure out where to insert the tab based on the bounds of the dragged |
1151 // representation and the ideal bounds of the other Tabs already in the | 1151 // representation and the ideal bounds of the other Tabs already in the |
1152 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are | 1152 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are |
1153 // changing due to animation). | 1153 // changing due to animation). |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 attached_tabstrip_->ReleaseDragController(); | 1222 attached_tabstrip_->ReleaseDragController(); |
1223 if (release_capture == RELEASE_CAPTURE) | 1223 if (release_capture == RELEASE_CAPTURE) |
1224 attached_tabstrip_->GetWidget()->ReleaseCapture(); | 1224 attached_tabstrip_->GetWidget()->ReleaseCapture(); |
1225 } | 1225 } |
1226 | 1226 |
1227 mouse_move_direction_ = kMovedMouseLeft | kMovedMouseRight; | 1227 mouse_move_direction_ = kMovedMouseLeft | kMovedMouseRight; |
1228 | 1228 |
1229 // Prevent the WebContents HWND from being hidden by any of the model | 1229 // Prevent the WebContents HWND from being hidden by any of the model |
1230 // operations performed during the drag. | 1230 // operations performed during the drag. |
1231 if (!detach_into_browser_) | 1231 if (!detach_into_browser_) |
1232 source_dragged_contents()->SetCapturingContents(true); | 1232 source_dragged_contents()->IncrementCapturerCount(); |
1233 | 1233 |
1234 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(0); | 1234 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(0); |
1235 TabStripModel* attached_model = GetModel(attached_tabstrip_); | 1235 TabStripModel* attached_model = GetModel(attached_tabstrip_); |
1236 std::vector<TabRendererData> tab_data; | 1236 std::vector<TabRendererData> tab_data; |
1237 for (size_t i = 0; i < drag_data_.size(); ++i) { | 1237 for (size_t i = 0; i < drag_data_.size(); ++i) { |
1238 tab_data.push_back(drag_data_[i].attached_tab->data()); | 1238 tab_data.push_back(drag_data_[i].attached_tab->data()); |
1239 int index = attached_model->GetIndexOfWebContents(drag_data_[i].contents); | 1239 int index = attached_model->GetIndexOfWebContents(drag_data_[i].contents); |
1240 DCHECK_NE(-1, index); | 1240 DCHECK_NE(-1, index); |
1241 | 1241 |
1242 // Hide the tab so that the user doesn't see it animate closed. | 1242 // Hide the tab so that the user doesn't see it animate closed. |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 GetModel(source_tabstrip_)->SetSelectionFromModel(initial_selection_model_); | 1656 GetModel(source_tabstrip_)->SetSelectionFromModel(initial_selection_model_); |
1657 | 1657 |
1658 // If we're not attached to any TabStrip, or attached to some other TabStrip, | 1658 // If we're not attached to any TabStrip, or attached to some other TabStrip, |
1659 // we need to restore the bounds of the original TabStrip's frame, in case | 1659 // we need to restore the bounds of the original TabStrip's frame, in case |
1660 // it has been hidden. | 1660 // it has been hidden. |
1661 if (restore_frame && !restore_bounds_.IsEmpty()) | 1661 if (restore_frame && !restore_bounds_.IsEmpty()) |
1662 source_tabstrip_->GetWidget()->SetBounds(restore_bounds_); | 1662 source_tabstrip_->GetWidget()->SetBounds(restore_bounds_); |
1663 | 1663 |
1664 if (detach_into_browser_ && source_tabstrip_) | 1664 if (detach_into_browser_ && source_tabstrip_) |
1665 source_tabstrip_->GetWidget()->Activate(); | 1665 source_tabstrip_->GetWidget()->Activate(); |
| 1666 |
| 1667 // Return the WebContents to normalcy. If the tab was attached to a |
| 1668 // TabStrip before the revert, the decrement has already occurred. |
| 1669 // If the tab was destroyed, don't attempt to dereference the |
| 1670 // WebContents pointer. |
| 1671 if (!detach_into_browser_ && !attached_tabstrip_ && source_dragged_contents()) |
| 1672 source_dragged_contents()->DecrementCapturerCount(); |
1666 } | 1673 } |
1667 | 1674 |
1668 void TabDragController::ResetSelection(TabStripModel* model) { | 1675 void TabDragController::ResetSelection(TabStripModel* model) { |
1669 DCHECK(model); | 1676 DCHECK(model); |
1670 ui::ListSelectionModel selection_model; | 1677 ui::ListSelectionModel selection_model; |
1671 bool has_one_valid_tab = false; | 1678 bool has_one_valid_tab = false; |
1672 for (size_t i = 0; i < drag_data_.size(); ++i) { | 1679 for (size_t i = 0; i < drag_data_.size(); ++i) { |
1673 // |contents| is NULL if a tab was deleted out from under us. | 1680 // |contents| is NULL if a tab was deleted out from under us. |
1674 if (drag_data_[i].contents) { | 1681 if (drag_data_[i].contents) { |
1675 int index = model->GetIndexOfWebContents(drag_data_[i].contents); | 1682 int index = model->GetIndexOfWebContents(drag_data_[i].contents); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 item.add_types = drag_data_[i].pinned ? TabStripModel::ADD_PINNED | 1808 item.add_types = drag_data_[i].pinned ? TabStripModel::ADD_PINNED |
1802 : TabStripModel::ADD_NONE; | 1809 : TabStripModel::ADD_NONE; |
1803 contentses.push_back(item); | 1810 contentses.push_back(item); |
1804 }; | 1811 }; |
1805 | 1812 |
1806 Browser* new_browser = | 1813 Browser* new_browser = |
1807 GetModel(source_tabstrip_)->delegate()->CreateNewStripWithContents( | 1814 GetModel(source_tabstrip_)->delegate()->CreateNewStripWithContents( |
1808 contentses, window_bounds, dock_info_, widget->IsMaximized()); | 1815 contentses, window_bounds, dock_info_, widget->IsMaximized()); |
1809 ResetSelection(new_browser->tab_strip_model()); | 1816 ResetSelection(new_browser->tab_strip_model()); |
1810 new_browser->window()->Show(); | 1817 new_browser->window()->Show(); |
| 1818 |
| 1819 // Return the WebContents to normalcy. |
| 1820 if (!detach_into_browser_) |
| 1821 source_dragged_contents()->DecrementCapturerCount(); |
1811 } | 1822 } |
1812 | 1823 |
1813 CleanUpHiddenFrame(); | 1824 CleanUpHiddenFrame(); |
1814 } | 1825 } |
1815 | 1826 |
1816 void TabDragController::ResetDelegates() { | 1827 void TabDragController::ResetDelegates() { |
1817 DCHECK(!detach_into_browser_); | 1828 DCHECK(!detach_into_browser_); |
1818 for (size_t i = 0; i < drag_data_.size(); ++i) { | 1829 for (size_t i = 0; i < drag_data_.size(); ++i) { |
1819 if (drag_data_[i].contents && | 1830 if (drag_data_[i].contents && |
1820 drag_data_[i].contents->GetDelegate() == this) { | 1831 drag_data_[i].contents->GetDelegate() == this) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 gfx::Vector2d TabDragController::GetWindowOffset( | 2055 gfx::Vector2d TabDragController::GetWindowOffset( |
2045 const gfx::Point& point_in_screen) { | 2056 const gfx::Point& point_in_screen) { |
2046 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 2057 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
2047 attached_tabstrip_ : source_tabstrip_; | 2058 attached_tabstrip_ : source_tabstrip_; |
2048 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2059 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
2049 | 2060 |
2050 gfx::Point point = point_in_screen; | 2061 gfx::Point point = point_in_screen; |
2051 views::View::ConvertPointFromScreen(toplevel_view, &point); | 2062 views::View::ConvertPointFromScreen(toplevel_view, &point); |
2052 return point.OffsetFromOrigin(); | 2063 return point.OffsetFromOrigin(); |
2053 } | 2064 } |
OLD | NEW |