172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Use of this source code is governed by a BSD-style license that can be
372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// found in the LICENSE file.
472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#ifndef CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#define CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#pragma once
872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/views/tabs/base_tab_strip.h"
1072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass TouchTab;
1272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen///////////////////////////////////////////////////////////////////////////////
1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//
1572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// TouchTabStrip
1672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//
1772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//  A View that represents the TabStripModel. The TouchTabStrip has the
1872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//  following responsibilities:
1972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//    - It implements the TabStripModelObserver interface, and acts as a
2072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//      container for Tabs, and is also responsible for creating them.
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen//
22ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// TODO(wyck): Use transformable views for scrolling.
2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen///////////////////////////////////////////////////////////////////////////////
2472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass TouchTabStrip : public BaseTabStrip {
2572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen public:
2672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  explicit TouchTabStrip(TabStripController* controller);
2772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ~TouchTabStrip();
2872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
29ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // AbstractTabStripView implementation:
3072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual bool IsPositionInWindowCaption(const gfx::Point& point);
31ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void SetBackgroundOffset(const gfx::Point& offset);
32ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
33ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // BaseTabStrip implementation:
3472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void PrepareForCloseAt(int model_index);
3572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void StartHighlight(int model_index);
3672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void StopAllHighlighting();
3772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual BaseTab* CreateTabForDragging();
3872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void RemoveTabAt(int model_index);
3972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void SelectTabAt(int old_model_index, int new_model_index);
4072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void TabTitleChangedNotLoading(int model_index);
4172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual BaseTab* CreateTab();
42ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void StartInsertTabAnimation(int model_index);
4372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void AnimateToIdealBounds();
4472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual bool ShouldHighlightCloseButtonAfterRemove();
4572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void GenerateIdealBounds();
46ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void LayoutDraggedTabsAt(const std::vector<BaseTab*>& tabs,
47ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                   BaseTab* active_tab,
48ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                   const gfx::Point& location,
49ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                   bool initial_drag);
50ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void CalculateBoundsForDraggedTabs(
51ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      const std::vector<BaseTab*>& tabs,
52ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      std::vector<gfx::Rect>* bounds);
53ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual int GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs);
5472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
55ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // views::View overrides:
56ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
57ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
58ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
59ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void OnMouseCaptureLost() OVERRIDE;
6072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
6172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Retrieves the Tab at the specified index. Remember, the specified index
6272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // is in terms of tab_data, *not* the model.
6372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  TouchTab* GetTabAtTabDataIndex(int tab_data_index) const;
6472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
6572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen private:
6672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void Init();
6772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
68ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Overridden from views::View.
69ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual gfx::Size GetPreferredSize() OVERRIDE;
70ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
71ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual views::View::TouchStatus OnTouchEvent(
72ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      const views::TouchEvent& event) OVERRIDE;
73ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void ViewHierarchyChanged(bool is_add,
74ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                    View* parent,
75ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                    View* child) OVERRIDE;
76ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
77ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Adjusts the state of scroll interaction when a mouse press occurs at the
78ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // given point.  Sets an appropriate |initial_scroll_offset_|.
79ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void BeginScroll(const gfx::Point& point);
80ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
81ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Adjusts the state of scroll interaction when the mouse is dragged to the
82ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // given point.  If the scroll is not beyond the minimum threshold, the tabs
83ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // will not actually scroll.
84ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void ContinueScroll(const gfx::Point& point);
85ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
86ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Adjusts the state of scroll interaction when the mouse is released.  Either
87ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // scrolls to the final mouse release point or selects the current tab
88ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // depending on whether the mouse was dragged beyone the minimum threshold.
89ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void EndScroll(const gfx::Point& point);
90ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
91ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Adjust the state of scroll interaction when the mouse capture is lost.  It
92ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // scrolls back to the original position before the scroll began.
93ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void CancelScroll();
94ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
95ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Adjust the positions of the tabs to perform a scroll of |delta_x| relative
96ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // to the |initial_scroll_offset_|.
97ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void ScrollTo(int delta_x);
98ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
9972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // True if PrepareForCloseAt has been invoked. When true remove animations
10072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // preserve current tab bounds.
10172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  bool in_tab_close_;
10272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
103ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Last time the tabstrip was tapped.
104ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  base::Time last_tap_time_;
105ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
106ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // The view that was tapped last.
107ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  View* last_tapped_view_;
108ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
109ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Records the mouse x coordinate at the start of a drag operation.
110ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  int initial_mouse_x_;
111ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
112ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Records the scroll offset at the time of the start of a drag operation.
113ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  int initial_scroll_offset_;
114ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
115ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // The current offset of the view.  Positive scroll offsets move the icons to
116ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // the left.  Negative scroll offsets move the icons to the right.
117ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  int scroll_offset_;
118ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
119ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // State of the scrolling interaction.  Will be true once the drag has been
120ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // displaced beyond the minimum dragging threshold.
121ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  bool scrolling_;
122ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
123ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Records the tab that was under the initial mouse press.  Must match the
124ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // tab that was under the final mouse release in order for the tab to
125ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // be selected.
126ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  TouchTab* initial_tab_;
127ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
128ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // The minimum value that |scroll_offset_| can have.  Based on the total
129ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // width of all the content to be scrolled, less the viewport size.
130ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  int min_scroll_offset_;
131ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
13272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  DISALLOW_COPY_AND_ASSIGN(TouchTabStrip);
13372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen};
13472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
13572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#endif  // CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_STRIP_H_
136