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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 newtab_button_(NULL), | 580 newtab_button_(NULL), |
581 current_unselected_width_(Tab::GetStandardSize().width()), | 581 current_unselected_width_(Tab::GetStandardSize().width()), |
582 current_selected_width_(Tab::GetStandardSize().width()), | 582 current_selected_width_(Tab::GetStandardSize().width()), |
583 available_width_for_tabs_(-1), | 583 available_width_for_tabs_(-1), |
584 in_tab_close_(false), | 584 in_tab_close_(false), |
585 animation_container_(new ui::AnimationContainer()), | 585 animation_container_(new ui::AnimationContainer()), |
586 ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)), | 586 ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)), |
587 layout_type_(TAB_STRIP_LAYOUT_SHRINK), | 587 layout_type_(TAB_STRIP_LAYOUT_SHRINK), |
588 adjust_layout_(false), | 588 adjust_layout_(false), |
589 reset_to_shrink_on_exit_(false), | 589 reset_to_shrink_on_exit_(false), |
590 was_dragging_(false), | |
591 had_gesture_long_press_(false), | |
590 mouse_move_count_(0), | 592 mouse_move_count_(0), |
591 immersive_style_(false) { | 593 immersive_style_(false) { |
592 Init(); | 594 Init(); |
593 } | 595 } |
594 | 596 |
595 TabStrip::~TabStrip() { | 597 TabStrip::~TabStrip() { |
596 FOR_EACH_OBSERVER(TabStripObserver, observers_, | 598 FOR_EACH_OBSERVER(TabStripObserver, observers_, |
597 TabStripDeleted(this)); | 599 TabStripDeleted(this)); |
598 | 600 |
599 // The animations may reference the tabs. Shut down the animation before we | 601 // The animations may reference the tabs. Shut down the animation before we |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1493 | 1495 |
1494 void TabStrip::OnGestureEvent(ui::GestureEvent* event) { | 1496 void TabStrip::OnGestureEvent(ui::GestureEvent* event) { |
1495 SetResetToShrinkOnExit(false); | 1497 SetResetToShrinkOnExit(false); |
1496 switch (event->type()) { | 1498 switch (event->type()) { |
1497 case ui::ET_GESTURE_END: | 1499 case ui::ET_GESTURE_END: |
1498 EndDrag(END_DRAG_COMPLETE); | 1500 EndDrag(END_DRAG_COMPLETE); |
1499 if (adjust_layout_) { | 1501 if (adjust_layout_) { |
1500 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); | 1502 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); |
1501 controller_->LayoutTypeMaybeChanged(); | 1503 controller_->LayoutTypeMaybeChanged(); |
1502 } | 1504 } |
1505 // If there was long press gesture and no dragging, | |
1506 // show the context menu at finger lift. | |
1507 if (!was_dragging_ && had_gesture_long_press_) { | |
1508 Tab* tab = FindTabForEvent(last_long_press_location_); | |
1509 if (tab) { | |
1510 gfx::Point local_point(last_long_press_location_); | |
1511 ConvertPointToScreen(this, &local_point); | |
1512 ShowContextMenuForTab(tab, local_point); | |
sadrul
2013/03/19 22:17:31
The finger may have moved a significant distance a
Yufeng Shen (Slow to review)
2013/03/19 23:37:38
If the finger has moved a significant distance, th
| |
1513 } | |
1514 } | |
1515 had_gesture_long_press_ = false; | |
1516 was_dragging_ = false; | |
1503 break; | 1517 break; |
1504 | 1518 |
1505 case ui::ET_GESTURE_LONG_PRESS: | 1519 case ui::ET_GESTURE_LONG_PRESS: |
1506 if (drag_controller_.get()) | 1520 if (drag_controller_.get()) |
1507 drag_controller_->SetMoveBehavior(TabDragController::REORDER); | 1521 drag_controller_->SetMoveBehavior(TabDragController::REORDER); |
1522 had_gesture_long_press_ = true; | |
1523 last_long_press_location_ = event->location(); | |
1508 break; | 1524 break; |
1509 | 1525 |
1510 case ui::ET_GESTURE_SCROLL_UPDATE: | 1526 case ui::ET_GESTURE_SCROLL_UPDATE: |
1511 ContinueDrag(this, *event); | 1527 ContinueDrag(this, *event); |
1528 was_dragging_ = true; | |
1512 break; | 1529 break; |
1513 | 1530 |
1514 case ui::ET_GESTURE_BEGIN: | 1531 case ui::ET_GESTURE_BEGIN: |
1515 EndDrag(END_DRAG_CANCEL); | 1532 EndDrag(END_DRAG_CANCEL); |
1516 break; | 1533 break; |
1517 | 1534 |
1518 default: | 1535 default: |
1519 break; | 1536 break; |
1520 } | 1537 } |
1521 event->SetHandled(); | 1538 event->SetHandled(); |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2486 | 2503 |
2487 int TabStrip::GetStartXForNormalTabs() const { | 2504 int TabStrip::GetStartXForNormalTabs() const { |
2488 int mini_tab_count = GetMiniTabCount(); | 2505 int mini_tab_count = GetMiniTabCount(); |
2489 if (mini_tab_count == 0) | 2506 if (mini_tab_count == 0) |
2490 return 0; | 2507 return 0; |
2491 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 2508 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + |
2492 kMiniToNonMiniGap; | 2509 kMiniToNonMiniGap; |
2493 } | 2510 } |
2494 | 2511 |
2495 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 2512 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { |
2496 DCHECK(touch_layout_.get()); | |
2497 int active_tab_index = touch_layout_->active_index(); | |
2498 Tab* tab = NULL; | 2513 Tab* tab = NULL; |
2499 if (active_tab_index != -1) { | 2514 if (touch_layout_.get()) { |
2500 tab = FindTabForEventFrom(point, active_tab_index, -1); | 2515 int active_tab_index = touch_layout_->active_index(); |
2501 if (!tab) | 2516 if (active_tab_index != -1) { |
2502 tab = FindTabForEventFrom(point, active_tab_index + 1, 1); | 2517 tab = FindTabForEventFrom(point, active_tab_index, -1); |
2503 } else if (tab_count()) { | 2518 if (!tab) |
2504 tab = FindTabForEventFrom(point, 0, 1); | 2519 tab = FindTabForEventFrom(point, active_tab_index + 1, 1); |
2520 } else if (tab_count()) { | |
2521 tab = FindTabForEventFrom(point, 0, 1); | |
2522 } | |
2523 } else { | |
2524 for (int i = 0; i < tab_count(); ++i) { | |
2525 if (IsPointInTab(tab_at(i), point)) { | |
2526 tab = tab_at(i); | |
2527 break; | |
2528 } | |
2529 } | |
2505 } | 2530 } |
2506 return tab; | 2531 return tab; |
2507 } | 2532 } |
2508 | 2533 |
2509 Tab* TabStrip::FindTabForEventFrom(const gfx::Point& point, | 2534 Tab* TabStrip::FindTabForEventFrom(const gfx::Point& point, |
2510 int start, | 2535 int start, |
2511 int delta) { | 2536 int delta) { |
2512 // |start| equals tab_count() when there are only pinned tabs. | 2537 // |start| equals tab_count() when there are only pinned tabs. |
2513 if (start == tab_count()) | 2538 if (start == tab_count()) |
2514 start += delta; | 2539 start += delta; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2593 if (!adjust_layout_) | 2618 if (!adjust_layout_) |
2594 return false; | 2619 return false; |
2595 | 2620 |
2596 #if !defined(OS_CHROMEOS) | 2621 #if !defined(OS_CHROMEOS) |
2597 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2622 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2598 return false; | 2623 return false; |
2599 #endif | 2624 #endif |
2600 | 2625 |
2601 return true; | 2626 return true; |
2602 } | 2627 } |
OLD | NEW |