Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
      6 #define CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/ui/views/tabs/base_tab_strip.h"
     10 
     11 class TouchTab;
     12 
     13 ///////////////////////////////////////////////////////////////////////////////
     14 //
     15 // TouchTabStrip
     16 //
     17 //  A View that represents the TabStripModel. The TouchTabStrip has the
     18 //  following responsibilities:
     19 //    - It implements the TabStripModelObserver interface, and acts as a
     20 //      container for Tabs, and is also responsible for creating them.
     21 //
     22 // TODO(wyck): Use transformable views for scrolling.
     23 ///////////////////////////////////////////////////////////////////////////////
     24 class TouchTabStrip : public BaseTabStrip {
     25  public:
     26   explicit TouchTabStrip(TabStripController* controller);
     27   virtual ~TouchTabStrip();
     28 
     29   // AbstractTabStripView implementation:
     30   virtual bool IsPositionInWindowCaption(const gfx::Point& point);
     31   virtual void SetBackgroundOffset(const gfx::Point& offset);
     32 
     33   // BaseTabStrip implementation:
     34   virtual void PrepareForCloseAt(int model_index);
     35   virtual void StartHighlight(int model_index);
     36   virtual void StopAllHighlighting();
     37   virtual BaseTab* CreateTabForDragging();
     38   virtual void RemoveTabAt(int model_index);
     39   virtual void SelectTabAt(int old_model_index, int new_model_index);
     40   virtual void TabTitleChangedNotLoading(int model_index);
     41   virtual BaseTab* CreateTab();
     42   virtual void StartInsertTabAnimation(int model_index);
     43   virtual void AnimateToIdealBounds();
     44   virtual bool ShouldHighlightCloseButtonAfterRemove();
     45   virtual void GenerateIdealBounds();
     46   virtual void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs,
     47                                    BaseTab* active_tab,
     48                                    const gfx::Point& location,
     49                                    bool initial_drag);
     50   virtual void CalculateBoundsForDraggedTabs(
     51       const std::vector<BaseTab*>& tabs,
     52       std::vector<gfx::Rect>* bounds);
     53   virtual int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs);
     54 
     55   // views::View overrides:
     56   virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
     57   virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
     58   virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
     59   virtual void OnMouseCaptureLost() OVERRIDE;
     60 
     61   // Retrieves the Tab at the specified index. Remember, the specified index
     62   // is in terms of tab_data, *not* the model.
     63   TouchTab* GetTabAtTabDataIndex(int tab_data_index) const;
     64 
     65  private:
     66   void Init();
     67 
     68   // Overridden from views::View.
     69   virtual gfx::Size GetPreferredSize() OVERRIDE;
     70   virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
     71   virtual views::View::TouchStatus OnTouchEvent(
     72       const views::TouchEvent& event) OVERRIDE;
     73   virtual void ViewHierarchyChanged(bool is_add,
     74                                     View* parent,
     75                                     View* child) OVERRIDE;
     76 
     77   // Adjusts the state of scroll interaction when a mouse press occurs at the
     78   // given point.  Sets an appropriate |initial_scroll_offset_|.
     79   void BeginScroll(const gfx::Point& point);
     80 
     81   // Adjusts the state of scroll interaction when the mouse is dragged to the
     82   // given point.  If the scroll is not beyond the minimum threshold, the tabs
     83   // will not actually scroll.
     84   void ContinueScroll(const gfx::Point& point);
     85 
     86   // Adjusts the state of scroll interaction when the mouse is released.  Either
     87   // scrolls to the final mouse release point or selects the current tab
     88   // depending on whether the mouse was dragged beyone the minimum threshold.
     89   void EndScroll(const gfx::Point& point);
     90 
     91   // Adjust the state of scroll interaction when the mouse capture is lost.  It
     92   // scrolls back to the original position before the scroll began.
     93   void CancelScroll();
     94 
     95   // Adjust the positions of the tabs to perform a scroll of |delta_x| relative
     96   // to the |initial_scroll_offset_|.
     97   void ScrollTo(int delta_x);
     98 
     99   // True if PrepareForCloseAt has been invoked. When true remove animations
    100   // preserve current tab bounds.
    101   bool in_tab_close_;
    102 
    103   // Last time the tabstrip was tapped.
    104   base::Time last_tap_time_;
    105 
    106   // The view that was tapped last.
    107   View* last_tapped_view_;
    108 
    109   // Records the mouse x coordinate at the start of a drag operation.
    110   int initial_mouse_x_;
    111 
    112   // Records the scroll offset at the time of the start of a drag operation.
    113   int initial_scroll_offset_;
    114 
    115   // The current offset of the view.  Positive scroll offsets move the icons to
    116   // the left.  Negative scroll offsets move the icons to the right.
    117   int scroll_offset_;
    118 
    119   // State of the scrolling interaction.  Will be true once the drag has been
    120   // displaced beyond the minimum dragging threshold.
    121   bool scrolling_;
    122 
    123   // Records the tab that was under the initial mouse press.  Must match the
    124   // tab that was under the final mouse release in order for the tab to
    125   // be selected.
    126   TouchTab* initial_tab_;
    127 
    128   // The minimum value that |scroll_offset_| can have.  Based on the total
    129   // width of all the content to be scrolled, less the viewport size.
    130   int min_scroll_offset_;
    131 
    132   DISALLOW_COPY_AND_ASSIGN(TouchTabStrip);
    133 };
    134 
    135 #endif  // CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
    136