summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/tabs/tab_strip_2.h
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 18:44:31 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-07 18:44:31 +0000
commit7c0560f904487819f2c408c87899d1ccfa91c1fe (patch)
treeda949466cd6dd09f5ce575b206a65b6ba0e1a2f9 /chrome/browser/views/tabs/tab_strip_2.h
parent93a2c7241cddc33af51cdc3daea03e414f544ec8 (diff)
downloadchromium_src-7c0560f904487819f2c408c87899d1ccfa91c1fe.zip
chromium_src-7c0560f904487819f2c408c87899d1ccfa91c1fe.tar.gz
chromium_src-7c0560f904487819f2c408c87899d1ccfa91c1fe.tar.bz2
Basics of a new TabStrip.It's very, very rough, but I wanted to check it in so I don't have to keep typing svn pset as I pass patches back and forth between machines.Behind a command line flag --enable-tabtastic2.I'm trying to split the TabContents specific stuff off of the TabStrip so it's more generic (and more easily mocked for unit testing of various layout conditions). Hence TabStrip vs. BrowserTabStrip. TabStrip may move into views/ once this process is complete.Animator is a utility that can be associated with a View that (at this point) animates that View's bounds from wherever it is now to somewhere else. The TabStrip uses this to do animations for individual Tabs that are independent of each other - a limitation of the old TabStrip is that only one animation is ever active at a time so its animations are a little jumpy compared to other products.Also, detached tab dragging shows the live contents, with all animations/video/etc.Like I said, this is really rough, but I didn't want it to grow any bigger. I will write up a design doc later.http://crbug.com/9032TEST=TBD... will finally be doing some for TabStrip layout!
Review URL: http://codereview.chromium.org/42490 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20053 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/tabs/tab_strip_2.h')
-rw-r--r--chrome/browser/views/tabs/tab_strip_2.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/chrome/browser/views/tabs/tab_strip_2.h b/chrome/browser/views/tabs/tab_strip_2.h
new file mode 100644
index 0000000..7bbce90
--- /dev/null
+++ b/chrome/browser/views/tabs/tab_strip_2.h
@@ -0,0 +1,163 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
+#define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_
+
+#include <vector>
+
+#include "base/task.h"
+#include "chrome/browser/views/tabs/tab_2.h"
+#include "views/animator.h"
+#include "views/view.h"
+
+namespace gfx {
+class Canvas;
+}
+
+// An interface implemented by an object that provides state for objects in the
+// TabStrip2. This object is never owned by the TabStrip2.
+// TODO(beng): maybe TabStrip2Delegate?
+class TabStrip2Model {
+ public:
+ // Get presentation state for a particular Tab2.
+ virtual string16 GetTitle(int index) const = 0;
+ virtual bool IsSelected(int index) const = 0;
+
+ // The Tab2 at the specified index has been selected.
+ virtual void SelectTabAt(int index) = 0;
+
+ // Returns true if Tab2s can be dragged.
+ virtual bool CanDragTabs() const = 0;
+
+ // The Tab2 at the specified source index has moved to the specified
+ // destination index.
+ virtual void MoveTabAt(int index, int to_index) = 0;
+
+ // The Tab2 at the specified index was detached. |window_bounds| are the
+ // screen bounds of the current window, and |tab_bounds| are the bounds of the
+ // Tab2 in screen coordinates.
+ virtual void DetachTabAt(int index,
+ const gfx::Rect& window_bounds,
+ const gfx::Rect& tab_bounds) = 0;
+};
+
+// A TabStrip view.
+class TabStrip2 : public views::View,
+ public Tab2Model,
+ public views::AnimatorDelegate {
+ public:
+ explicit TabStrip2(TabStrip2Model* model);
+ virtual ~TabStrip2();
+
+ // Returns true if the new TabStrip is enabled.
+ static bool Enabled();
+
+ // API for adding, removing, selecting and moving tabs around.
+ void AddTabAt(int index);
+ void RemoveTabAt(int index, Tab2Model* removing_model);
+ void SelectTabAt(int index);
+ void MoveTabAt(int index, int to_index);
+
+ int GetTabCount() const;
+ Tab2* GetTabAt(int index) const;
+ int GetTabIndex(Tab2* tab) const;
+
+ // Returns the index to insert an item into the TabStrip at for a drop at the
+ // specified point in TabStrip coordinates.
+ int GetInsertionIndexForPoint(const gfx::Point& point) const;
+
+ // Returns the bounds of the Tab2 under |screen_point| in screen coordinates.
+ gfx::Rect GetDraggedTabScreenBounds(const gfx::Point& screen_point);
+
+ // Sets the bounds of the Tab2 at the specified index to |tab_bounds|.
+ void SetDraggedTabBounds(int index, const gfx::Rect& tab_bounds);
+
+ // Animates the dragged Tab2 to the location implied by its index in the
+ // model.
+ void SendDraggedTabHome();
+
+ // Continue a drag operation on the Tab2 at the specified index.
+ void ResumeDraggingTab(int index, const gfx::Rect& tab_bounds);
+
+ // Returns true if the mouse pointer at the specified point (screen bounds)
+ // constitutes a rearrange rather than a detach.
+ static bool IsDragRearrange(TabStrip2* tabstrip,
+ const gfx::Point& screen_point);
+
+ // Overridden from Tab2Model:
+ virtual string16 GetTitle(Tab2* tab) const;
+ virtual bool IsSelected(Tab2* tab) const;
+ virtual void SelectTab(Tab2* tab);
+ virtual void CaptureDragInfo(Tab2* tab, const views::MouseEvent& drag_event);
+ virtual bool DragTab(Tab2* tab, const views::MouseEvent& drag_event);
+ virtual void DragEnded(Tab2* tab);
+ virtual views::AnimatorDelegate* AsAnimatorDelegate();
+
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+ virtual void Paint(gfx::Canvas* canvas);
+
+ private:
+ virtual void PaintChildren(gfx::Canvas* canvas);
+
+ // Overridden from views::AnimatorDelegate:
+ virtual views::View* GetClampedView(views::View* host);
+ virtual void AnimationCompletedForHost(View* host);
+
+ // Specifies what kind of TabStrip2 operation initiated the Layout, so the
+ // heuristic can adapt accordingly.
+ enum LayoutSource {
+ LS_TAB_ADD,
+ LS_TAB_REMOVE,
+ LS_TAB_SELECT,
+ LS_TAB_DRAG_REORDER,
+ LS_TAB_DRAG_NORMALIZE,
+ LS_OTHER
+ };
+
+ // Returns the animation directions for the specified layout source event.
+ int GetAnimateFlagsForLayoutSource(LayoutSource source) const;
+
+ // Lays out the contents of the TabStrip2.
+ void LayoutImpl(LayoutSource source);
+
+ // Execute the tab detach operation after a return to the message loop.
+ void DragDetachTabImpl(Tab2* tab, int index);
+
+ // Execute the drag initiation operation after a return to the message loop.
+ void StartDragTabImpl(int index, const gfx::Rect& tab_bounds);
+
+ // Returns the index into |tabs_| that corresponds to a publicly visible
+ // index. The index spaces are different since when a tab is closed we retain
+ // the tab in the presentation (and this our tab vector) until the tab has
+ // animated itself out of existence, but the clients of our API expect that
+ // index to be synchronously removed.
+ int GetInternalIndex(int public_index) const;
+
+ TabStrip2Model* model_;
+
+ // A vector of our Tabs. Stored separately from the child views, the child
+ // view order does not map directly to the presentation order, and because
+ // we can have child views that aren't Tab2s.
+ std::vector<Tab2*> tabs_;
+
+ // The position of the mouse relative to the widget when drag information was
+ // captured.
+ gfx::Point mouse_tab_offset_;
+
+ // The last position of the mouse along the horizontal axis of the TabStrip
+ // prior to the current drag event. Used to determine that the mouse has moved
+ // beyond the minimum horizontal threshold to initiate a drag operation.
+ int last_move_screen_x_;
+
+ // Factories to help break up work and avoid nesting message loops.
+ ScopedRunnableMethodFactory<TabStrip2> detach_factory_;
+ ScopedRunnableMethodFactory<TabStrip2> drag_start_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabStrip2);
+};
+
+#endif // #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_2_H_