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_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 DoLayout(); | 503 DoLayout(); |
504 } | 504 } |
505 | 505 |
506 void TabStrip::MoveTab(int from_model_index, | 506 void TabStrip::MoveTab(int from_model_index, |
507 int to_model_index, | 507 int to_model_index, |
508 const TabRendererData& data) { | 508 const TabRendererData& data) { |
509 DCHECK_GT(tabs_.view_size(), 0); | 509 DCHECK_GT(tabs_.view_size(), 0); |
510 BaseTab* last_tab = tab_at(tab_count() - 1); | 510 BaseTab* last_tab = tab_at(tab_count() - 1); |
511 tab_at(from_model_index)->SetData(data); | 511 tab_at(from_model_index)->SetData(data); |
512 if (touch_layout_.get()) { | 512 if (touch_layout_.get()) { |
513 tabs_.Move(from_model_index, to_model_index); | 513 tabs_.MoveViewOnly(from_model_index, to_model_index); |
514 int mini_tab_count = 0; | 514 int mini_count = 0; |
515 int start_x = GenerateIdealBoundsForMiniTabs(&mini_tab_count); | 515 GenerateIdealBoundsForMiniTabs(&mini_count); |
516 touch_layout_->MoveTab( | 516 touch_layout_->MoveTab( |
517 from_model_index, to_model_index, controller_->GetActiveIndex(), | 517 from_model_index, to_model_index, controller_->GetActiveIndex(), |
518 start_x, mini_tab_count); | 518 GetStartXForNormalTabs(), mini_count); |
519 } else { | 519 } else { |
520 tabs_.Move(from_model_index, to_model_index); | 520 tabs_.Move(from_model_index, to_model_index); |
521 } | 521 } |
522 StartMoveTabAnimation(); | 522 StartMoveTabAnimation(); |
523 if (TabDragController::IsAttachedTo(this) && | 523 if (TabDragController::IsAttachedTo(this) && |
524 (last_tab != tab_at(tab_count() - 1) || last_tab->dragging())) { | 524 (last_tab != tab_at(tab_count() - 1) || last_tab->dragging())) { |
525 newtab_button_->SetVisible(false); | 525 newtab_button_->SetVisible(false); |
526 } | 526 } |
527 } | 527 } |
528 | 528 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 } | 789 } |
790 DCHECK(!tabs.empty()); | 790 DCHECK(!tabs.empty()); |
791 DCHECK(std::find(tabs.begin(), tabs.end(), tab) != tabs.end()); | 791 DCHECK(std::find(tabs.begin(), tabs.end(), tab) != tabs.end()); |
792 TabStripSelectionModel selection_model; | 792 TabStripSelectionModel selection_model; |
793 if (!original_selection.IsSelected(model_index)) | 793 if (!original_selection.IsSelected(model_index)) |
794 selection_model.Copy(original_selection); | 794 selection_model.Copy(original_selection); |
795 // Delete the existing DragController before creating a new one. We do this as | 795 // Delete the existing DragController before creating a new one. We do this as |
796 // creating the DragController remembers the WebContents delegates and we need | 796 // creating the DragController remembers the WebContents delegates and we need |
797 // to make sure the existing DragController isn't still a delegate. | 797 // to make sure the existing DragController isn't still a delegate. |
798 drag_controller_.reset(); | 798 drag_controller_.reset(); |
| 799 // TODO(sky): verify ET_TOUCH_PRESSED is right. |
| 800 bool move_only = touch_layout_.get() && |
| 801 (event.type() == ui::ET_TOUCH_PRESSED || |
| 802 (event.type() == ui::ET_MOUSE_PRESSED && |
| 803 event.flags() & ui::EF_CONTROL_DOWN)); |
799 drag_controller_.reset(TabDragController::Create( | 804 drag_controller_.reset(TabDragController::Create( |
800 this, tab, tabs, gfx::Point(x, y), tab->GetMirroredXInView(event.x()), | 805 this, tab, tabs, gfx::Point(x, y), tab->GetMirroredXInView(event.x()), |
801 selection_model, touch_layout_.get() != NULL)); | 806 selection_model, move_only)); |
802 // TODO: Instead of touch layout need to look at event type, eg | |
803 // event.type() == ui::ET_TOUCH_PRESSED)), and need to plumb through long | |
804 // press and touch stuff. | |
805 } | 807 } |
806 | 808 |
807 void TabStrip::ContinueDrag(const views::MouseEvent& event) { | 809 void TabStrip::ContinueDrag(const views::MouseEvent& event) { |
808 if (drag_controller_.get()) | 810 if (drag_controller_.get()) |
809 drag_controller_->Drag(); | 811 drag_controller_->Drag(); |
810 } | 812 } |
811 | 813 |
812 bool TabStrip::EndDrag(bool canceled) { | 814 bool TabStrip::EndDrag(bool canceled) { |
813 if (!drag_controller_.get()) | 815 if (!drag_controller_.get()) |
814 return false; | 816 return false; |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 set_ideal_bounds(i, bounds); | 1319 set_ideal_bounds(i, bounds); |
1318 } | 1320 } |
1319 touch_layout_->DragActiveTab(delta); | 1321 touch_layout_->DragActiveTab(delta); |
1320 DoLayout(); | 1322 DoLayout(); |
1321 } | 1323 } |
1322 | 1324 |
1323 void TabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, | 1325 void TabStrip::LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs, |
1324 BaseTab* active_tab, | 1326 BaseTab* active_tab, |
1325 const gfx::Point& location, | 1327 const gfx::Point& location, |
1326 bool initial_drag) { | 1328 bool initial_drag) { |
1327 if (touch_layout_.get()) { | |
1328 touch_layout_->DragActiveTab(location.x() - active_tab->bounds().x()); | |
1329 DoLayout(); | |
1330 return; | |
1331 } | |
1332 // Immediately hide the new tab button if the last tab is being dragged. | 1329 // Immediately hide the new tab button if the last tab is being dragged. |
1333 if (tab_at(tab_count() - 1)->dragging()) | 1330 if (tab_at(tab_count() - 1)->dragging()) |
1334 newtab_button_->SetVisible(false); | 1331 newtab_button_->SetVisible(false); |
1335 std::vector<gfx::Rect> bounds; | 1332 std::vector<gfx::Rect> bounds; |
1336 CalculateBoundsForDraggedTabs(tabs, &bounds); | 1333 CalculateBoundsForDraggedTabs(tabs, &bounds); |
1337 DCHECK_EQ(tabs.size(), bounds.size()); | 1334 DCHECK_EQ(tabs.size(), bounds.size()); |
1338 int active_tab_model_index = GetModelIndexOfBaseTab(active_tab); | 1335 int active_tab_model_index = GetModelIndexOfBaseTab(active_tab); |
1339 int active_tab_index = static_cast<int>( | 1336 int active_tab_index = static_cast<int>( |
1340 std::find(tabs.begin(), tabs.end(), active_tab) - tabs.begin()); | 1337 std::find(tabs.begin(), tabs.end(), active_tab) - tabs.begin()); |
1341 for (size_t i = 0; i < tabs.size(); ++i) { | 1338 for (size_t i = 0; i < tabs.size(); ++i) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 } | 1944 } |
1948 return NULL; | 1945 return NULL; |
1949 } | 1946 } |
1950 | 1947 |
1951 std::vector<int> TabStrip::GetTabXCoordinates() { | 1948 std::vector<int> TabStrip::GetTabXCoordinates() { |
1952 std::vector<int> results; | 1949 std::vector<int> results; |
1953 for (int i = 0; i < tab_count(); ++i) | 1950 for (int i = 0; i < tab_count(); ++i) |
1954 results.push_back(ideal_bounds(i).x()); | 1951 results.push_back(ideal_bounds(i).x()); |
1955 return results; | 1952 return results; |
1956 } | 1953 } |
OLD | NEW |