| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ |
| 6 #define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ | 6 #define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ |
| 7 | 7 |
| 8 #include <vector> | |
| 9 | |
| 10 #include "app/animation_container.h" | 8 #include "app/animation_container.h" |
| 11 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 12 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 13 #include "base/timer.h" | 11 #include "base/timer.h" |
| 14 #include "chrome/browser/views/tabs/base_tab_strip.h" | 12 #include "chrome/browser/views/tabs/base_tab_strip.h" |
| 15 #include "chrome/browser/views/tabs/tab.h" | 13 #include "chrome/browser/views/tabs/tab.h" |
| 16 #include "gfx/point.h" | 14 #include "gfx/point.h" |
| 17 #include "gfx/rect.h" | 15 #include "gfx/rect.h" |
| 18 #include "views/animation/bounds_animator.h" | 16 #include "views/animation/bounds_animator.h" |
| 19 #include "views/controls/button/image_button.h" | 17 #include "views/controls/button/image_button.h" |
| 20 | 18 |
| 21 class DraggedTabController; | |
| 22 | |
| 23 namespace views { | 19 namespace views { |
| 24 class ImageView; | 20 class ImageView; |
| 25 #if defined(OS_LINUX) | 21 #if defined(OS_LINUX) |
| 26 class WidgetGtk; | 22 class WidgetGtk; |
| 27 #elif defined(OS_WIN) | 23 #elif defined(OS_WIN) |
| 28 class WidgetWin; | 24 class WidgetWin; |
| 29 #endif | 25 #endif |
| 30 } | 26 } |
| 31 | 27 |
| 32 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 // Set whether the new tab button is enabled. | 49 // Set whether the new tab button is enabled. |
| 54 void set_new_tab_button_enabled(bool enabled) { | 50 void set_new_tab_button_enabled(bool enabled) { |
| 55 new_tab_button_enabled_ = enabled; | 51 new_tab_button_enabled_ = enabled; |
| 56 } | 52 } |
| 57 | 53 |
| 58 // Returns whether the new tab button is enabled. | 54 // Returns whether the new tab button is enabled. |
| 59 bool new_tab_button_enabled() { | 55 bool new_tab_button_enabled() { |
| 60 return new_tab_button_enabled_; | 56 return new_tab_button_enabled_; |
| 61 } | 57 } |
| 62 | 58 |
| 63 // Destroys the active drag controller. | |
| 64 void DestroyDragController(); | |
| 65 | |
| 66 // Retrieves the ideal bounds for the Tab at the specified index. | |
| 67 gfx::Rect GetIdealBounds(int tab_data_index); | |
| 68 | |
| 69 // Creates the new tab button. | 59 // Creates the new tab button. |
| 70 void InitTabStripButtons(); | 60 void InitTabStripButtons(); |
| 71 | 61 |
| 72 // Returns the bounds of the new tab button. | 62 // Returns the bounds of the new tab button. |
| 73 gfx::Rect GetNewTabButtonBounds(); | 63 gfx::Rect GetNewTabButtonBounds(); |
| 74 | 64 |
| 75 // BaseTabStrip implementation: | 65 // BaseTabStrip implementation: |
| 76 virtual int GetPreferredHeight(); | 66 virtual int GetPreferredHeight(); |
| 77 virtual void SetBackgroundOffset(const gfx::Point& offset); | 67 virtual void SetBackgroundOffset(const gfx::Point& offset); |
| 78 virtual bool IsPositionInWindowCaption(const gfx::Point& point); | 68 virtual bool IsPositionInWindowCaption(const gfx::Point& point); |
| 79 virtual void SetDraggedTabBounds(int tab_index, | 69 virtual void SetDraggedTabBounds(int tab_index, |
| 80 const gfx::Rect& tab_bounds); | 70 const gfx::Rect& tab_bounds); |
| 81 virtual bool IsDragSessionActive() const; | |
| 82 virtual bool IsAnimating() const; | 71 virtual bool IsAnimating() const; |
| 83 virtual TabStrip* AsTabStrip(); | 72 virtual TabStrip* AsTabStrip(); |
| 84 virtual void AddTabAt(int model_index, | |
| 85 bool foreground, | |
| 86 const TabRendererData& data); | |
| 87 virtual void RemoveTabAt(int model_index, bool initiated_close); | 73 virtual void RemoveTabAt(int model_index, bool initiated_close); |
| 88 virtual void SelectTabAt(int old_model_index, int new_model_index); | 74 virtual void SelectTabAt(int old_model_index, int new_model_index); |
| 89 virtual void MoveTab(int from_model_index, int to_model_index); | |
| 90 virtual void TabTitleChangedNotLoading(int model_index); | 75 virtual void TabTitleChangedNotLoading(int model_index); |
| 91 virtual void SetTabData(int model_index, const TabRendererData& data); | 76 virtual void SetTabData(int model_index, const TabRendererData& data); |
| 92 virtual void StartHighlight(int model_index); | 77 virtual void StartHighlight(int model_index); |
| 93 virtual void StopAllHighlighting(); | 78 virtual void StopAllHighlighting(); |
| 94 virtual BaseTabRenderer* GetBaseTabAtModelIndex(int model_index) const; | |
| 95 virtual BaseTabRenderer* GetBaseTabAtTabIndex(int tab_index) const; | |
| 96 virtual int GetModelIndexOfBaseTab(const BaseTabRenderer* tab) const; | |
| 97 virtual BaseTabRenderer* CreateTabForDragging(); | 79 virtual BaseTabRenderer* CreateTabForDragging(); |
| 98 | 80 |
| 99 // views::View overrides: | 81 // views::View overrides: |
| 100 virtual void PaintChildren(gfx::Canvas* canvas); | 82 virtual void PaintChildren(gfx::Canvas* canvas); |
| 101 virtual views::View* GetViewByID(int id) const; | 83 virtual views::View* GetViewByID(int id) const; |
| 102 virtual void Layout(); | 84 virtual void Layout(); |
| 103 virtual gfx::Size GetPreferredSize(); | 85 virtual gfx::Size GetPreferredSize(); |
| 104 // NOTE: the drag and drop methods are invoked from FrameView. This is done to | 86 // NOTE: the drag and drop methods are invoked from FrameView. This is done to |
| 105 // allow for a drop region that extends outside the bounds of the TabStrip. | 87 // allow for a drop region that extends outside the bounds of the TabStrip. |
| 106 virtual void OnDragEntered(const views::DropTargetEvent& event); | 88 virtual void OnDragEntered(const views::DropTargetEvent& event); |
| 107 virtual int OnDragUpdated(const views::DropTargetEvent& event); | 89 virtual int OnDragUpdated(const views::DropTargetEvent& event); |
| 108 virtual void OnDragExited(); | 90 virtual void OnDragExited(); |
| 109 virtual int OnPerformDrop(const views::DropTargetEvent& event); | 91 virtual int OnPerformDrop(const views::DropTargetEvent& event); |
| 110 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); | 92 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); |
| 111 virtual views::View* GetViewForPoint(const gfx::Point& point); | 93 virtual views::View* GetViewForPoint(const gfx::Point& point); |
| 112 virtual void ThemeChanged(); | 94 virtual void ThemeChanged(); |
| 113 | 95 |
| 114 // BoundsAnimator::Observer overrides: | 96 // BoundsAnimator::Observer overrides: |
| 115 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator); | 97 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator); |
| 116 | 98 |
| 117 protected: | 99 protected: |
| 118 // Creates a new tab. | 100 // BaseTabStrip overrides: |
| 119 virtual Tab* CreateTab(); | 101 virtual Tab* CreateTab(); |
| 102 virtual void StartInsertTabAnimation(int model_index, bool foreground); |
| 103 virtual void StartMoveTabAnimation(); |
| 104 virtual void StartedDraggingTab(BaseTabRenderer* tab); |
| 105 virtual void StoppedDraggingTab(BaseTabRenderer* tab); |
| 120 | 106 |
| 121 // views::View implementation: | 107 // views::View implementation: |
| 122 virtual void ViewHierarchyChanged(bool is_add, | 108 virtual void ViewHierarchyChanged(bool is_add, |
| 123 views::View* parent, | 109 views::View* parent, |
| 124 views::View* child); | 110 views::View* child); |
| 125 virtual bool OnMouseDragged(const views::MouseEvent& event); | |
| 126 virtual void OnMouseReleased(const views::MouseEvent& event, | |
| 127 bool canceled); | |
| 128 | 111 |
| 129 // TabController overrides. | 112 // TabController overrides. |
| 130 virtual bool IsTabSelected(const BaseTabRenderer* btr) const; | 113 virtual bool IsTabSelected(const BaseTabRenderer* btr) const; |
| 131 virtual bool IsTabPinned(const BaseTabRenderer* btr) const; | |
| 132 virtual void MaybeStartDrag(BaseTabRenderer* btr, | |
| 133 const views::MouseEvent& event); | |
| 134 virtual void ContinueDrag(const views::MouseEvent& event); | |
| 135 virtual bool EndDrag(bool canceled); | |
| 136 virtual bool HasAvailableDragActions() const; | |
| 137 | 114 |
| 138 // views::ButtonListener implementation: | 115 // views::ButtonListener implementation: |
| 139 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 116 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 140 | 117 |
| 141 // MessageLoop::Observer implementation: | 118 // MessageLoop::Observer implementation: |
| 142 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 143 virtual void WillProcessMessage(const MSG& msg); | 120 virtual void WillProcessMessage(const MSG& msg); |
| 144 virtual void DidProcessMessage(const MSG& msg); | 121 virtual void DidProcessMessage(const MSG& msg); |
| 145 #else | 122 #else |
| 146 virtual void WillProcessEvent(GdkEvent* event); | 123 virtual void WillProcessEvent(GdkEvent* event); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 views::WidgetWin* arrow_window; | 184 views::WidgetWin* arrow_window; |
| 208 #else | 185 #else |
| 209 views::WidgetGtk* arrow_window; | 186 views::WidgetGtk* arrow_window; |
| 210 #endif | 187 #endif |
| 211 views::ImageView* arrow_view; | 188 views::ImageView* arrow_view; |
| 212 | 189 |
| 213 private: | 190 private: |
| 214 DISALLOW_COPY_AND_ASSIGN(DropInfo); | 191 DISALLOW_COPY_AND_ASSIGN(DropInfo); |
| 215 }; | 192 }; |
| 216 | 193 |
| 217 // The Tabs we contain, and their last generated "good" bounds. | |
| 218 struct TabData { | |
| 219 Tab* tab; | |
| 220 gfx::Rect ideal_bounds; | |
| 221 }; | |
| 222 | |
| 223 void Init(); | 194 void Init(); |
| 224 | 195 |
| 225 // Set the images for the new tab button. | 196 // Set the images for the new tab button. |
| 226 void LoadNewTabButtonImage(); | 197 void LoadNewTabButtonImage(); |
| 227 | 198 |
| 228 // Retrieves the Tab at the specified index. Remember, the specified index | 199 // Retrieves the Tab at the specified index. Remember, the specified index |
| 229 // is in terms of tab_data, *not* the model. | 200 // is in terms of tab_data, *not* the model. |
| 230 Tab* GetTabAtTabDataIndex(int tab_data_index) const; | 201 Tab* GetTabAtTabDataIndex(int tab_data_index) const; |
| 231 | 202 |
| 232 // Returns the tab at the specified index. If a remove animation is on going | 203 // Returns the tab at the specified index. If a remove animation is on going |
| 233 // and the index is >= the index of the tab being removed, the index is | 204 // and the index is >= the index of the tab being removed, the index is |
| 234 // incremented. While a remove operation is on going the indices of the model | 205 // incremented. While a remove operation is on going the indices of the model |
| 235 // do not line up with the indices of the view. This method adjusts the index | 206 // do not line up with the indices of the view. This method adjusts the index |
| 236 // accordingly. | 207 // accordingly. |
| 237 // | 208 // |
| 238 // Use this instead of GetTabAtTabDataIndex if the index comes from the model. | 209 // Use this instead of GetTabAtTabDataIndex if the index comes from the model. |
| 239 Tab* GetTabAtModelIndex(int model_index) const; | 210 Tab* GetTabAtModelIndex(int model_index) const; |
| 240 | 211 |
| 241 // Gets the number of Tabs in the collection. | |
| 242 // WARNING: this is the number of tabs displayed by the tabstrip, which if | |
| 243 // an animation is ongoing is not necessarily the same as the number of tabs | |
| 244 // in the model. | |
| 245 virtual int GetTabCount() const; | |
| 246 | |
| 247 // Returns the number of mini-tabs. | 212 // Returns the number of mini-tabs. |
| 248 int GetMiniTabCount() const; | 213 int GetMiniTabCount() const; |
| 249 | 214 |
| 250 // Returns the number of nano-tabs. | 215 // Returns the number of nano-tabs. |
| 251 int GetNanoTabCount() const; | 216 int GetNanoTabCount() const; |
| 252 | 217 |
| 253 // -- Tab Resize Layout ----------------------------------------------------- | 218 // -- Tab Resize Layout ----------------------------------------------------- |
| 254 | 219 |
| 255 // Returns the exact (unrounded) current width of each tab. | 220 // Returns the exact (unrounded) current width of each tab. |
| 256 void GetCurrentTabWidths(double* unselected_width, | 221 void GetCurrentTabWidths(double* unselected_width, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 void AnimateToIdealBounds(); | 285 void AnimateToIdealBounds(); |
| 321 | 286 |
| 322 // Returns true if a new tab inserted at specified index should start the | 287 // Returns true if a new tab inserted at specified index should start the |
| 323 // new tab animation. See description above AnimationType for details on | 288 // new tab animation. See description above AnimationType for details on |
| 324 // this animation. | 289 // this animation. |
| 325 bool ShouldStartIntertTabAnimationAtEnd(int model_index, bool foreground); | 290 bool ShouldStartIntertTabAnimationAtEnd(int model_index, bool foreground); |
| 326 | 291 |
| 327 // Starts various types of TabStrip animations. | 292 // Starts various types of TabStrip animations. |
| 328 void StartResizeLayoutAnimation(); | 293 void StartResizeLayoutAnimation(); |
| 329 void StartInsertTabAnimationAtEnd(); | 294 void StartInsertTabAnimationAtEnd(); |
| 330 void StartInsertTabAnimation(int model_index); | 295 void StartInsertTabAnimationImpl(int model_index); |
| 331 void StartRemoveTabAnimation(int model_index); | 296 void StartRemoveTabAnimation(int model_index); |
| 332 void StartMoveTabAnimation(int from_model_index, | 297 void StartMoveTabAnimation(int from_model_index, |
| 333 int to_model_index); | 298 int to_model_index); |
| 334 void StartMiniTabAnimation(); | 299 void StartMiniTabAnimation(); |
| 335 | 300 |
| 336 // Stops any ongoing animations. If |layout| is true and an animation is | 301 // Stops any ongoing animations. If |layout| is true and an animation is |
| 337 // ongoing this does a layout. | 302 // ongoing this does a layout. |
| 338 void StopAnimating(bool layout); | 303 virtual void StopAnimating(bool layout); |
| 339 | 304 |
| 340 // Resets all state related to animations. This is invoked when an animation | 305 // Resets all state related to animations. This is invoked when an animation |
| 341 // completes, prior to starting an animation or when we cancel an animation. | 306 // completes, prior to starting an animation or when we cancel an animation. |
| 342 // If |stop_new_tab_timer| is true, |new_tab_timer_| is stopped. | 307 // If |stop_new_tab_timer| is true, |new_tab_timer_| is stopped. |
| 343 void ResetAnimationState(bool stop_new_tab_timer); | 308 void ResetAnimationState(bool stop_new_tab_timer); |
| 344 | 309 |
| 345 // Calculates the available width for tabs, assuming a Tab is to be closed. | 310 // Calculates the available width for tabs, assuming a Tab is to be closed. |
| 346 int GetAvailableWidthForTabs(Tab* last_tab) const; | 311 int GetAvailableWidthForTabs(Tab* last_tab) const; |
| 347 | 312 |
| 348 // Returns true if the specified point in TabStrip coords is within the | 313 // Returns true if the specified point in TabStrip coords is within the |
| 349 // hit-test region of the specified Tab. | 314 // hit-test region of the specified Tab. |
| 350 bool IsPointInTab(Tab* tab, const gfx::Point& point_in_tabstrip_coords); | 315 bool IsPointInTab(Tab* tab, const gfx::Point& point_in_tabstrip_coords); |
| 351 | 316 |
| 352 // Cleans up the Tab from the TabStrip. This is called from the tab animation | |
| 353 // code and is not a general-purpose method. | |
| 354 void RemoveTab(Tab* tab); | |
| 355 | |
| 356 // Called from the message loop observer when a mouse movement has occurred | 317 // Called from the message loop observer when a mouse movement has occurred |
| 357 // anywhere over our containing window. | 318 // anywhere over our containing window. |
| 358 void HandleGlobalMouseMoveEvent(); | 319 void HandleGlobalMouseMoveEvent(); |
| 359 | 320 |
| 360 // Returns true if any of the tabs are phantom. | 321 // Returns true if any of the tabs are phantom. |
| 361 bool HasPhantomTabs() const; | 322 bool HasPhantomTabs() const; |
| 362 | 323 |
| 363 // Returns the index of the specified tab in the model coordiate system, or | |
| 364 // -1 if tab is closing or not in |tab_data_|. | |
| 365 int GetModelIndexOfTab(const Tab* tab) const; | |
| 366 | |
| 367 // Returns the index into |tab_data_| corresponding to the index from the | |
| 368 // TabStripModel, or |tab_data_.size()| if there is no tab representing | |
| 369 // |model_index|. | |
| 370 int ModelIndexToTabDataIndex(int model_index) const; | |
| 371 | |
| 372 // Returns the index into |tab_data_| corresponding to the specified tab, or | |
| 373 // -1 if the tab isn't in |tab_data_|. | |
| 374 int TabDataIndexOfTab(Tab* tab) const; | |
| 375 | |
| 376 // See description above field for details. | |
| 377 void set_attaching_dragged_tab(bool value) { attaching_dragged_tab_ = value; } | |
| 378 | |
| 379 // Used by DraggedTabController when the user starts or stops dragging a tab. | |
| 380 void StartedDraggingTab(Tab* tab); | |
| 381 void StoppedDraggingTab(Tab* tab); | |
| 382 | |
| 383 // -- Member Variables ------------------------------------------------------ | 324 // -- Member Variables ------------------------------------------------------ |
| 384 | 325 |
| 385 // A factory that is used to construct a delayed callback to the | 326 // A factory that is used to construct a delayed callback to the |
| 386 // ResizeLayoutTabsNow method. | 327 // ResizeLayoutTabsNow method. |
| 387 ScopedRunnableMethodFactory<TabStrip> resize_layout_factory_; | 328 ScopedRunnableMethodFactory<TabStrip> resize_layout_factory_; |
| 388 | 329 |
| 389 // True if the TabStrip has already been added as a MessageLoop observer. | 330 // True if the TabStrip has already been added as a MessageLoop observer. |
| 390 bool added_as_message_loop_observer_; | 331 bool added_as_message_loop_observer_; |
| 391 | 332 |
| 392 // True if a resize layout animation should be run a short delay after the | 333 // True if a resize layout animation should be run a short delay after the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 418 // The size of the new tab button must be hardcoded because we need to be | 359 // The size of the new tab button must be hardcoded because we need to be |
| 419 // able to lay it out before we are able to get its image from the | 360 // able to lay it out before we are able to get its image from the |
| 420 // ThemeProvider. It also makes sense to do this, because the size of the | 361 // ThemeProvider. It also makes sense to do this, because the size of the |
| 421 // new tab button should not need to be calculated dynamically. | 362 // new tab button should not need to be calculated dynamically. |
| 422 static const int kNewTabButtonWidth = 28; | 363 static const int kNewTabButtonWidth = 28; |
| 423 static const int kNewTabButtonHeight = 18; | 364 static const int kNewTabButtonHeight = 18; |
| 424 | 365 |
| 425 // Valid for the lifetime of a drag over us. | 366 // Valid for the lifetime of a drag over us. |
| 426 scoped_ptr<DropInfo> drop_info_; | 367 scoped_ptr<DropInfo> drop_info_; |
| 427 | 368 |
| 428 // The controller for a drag initiated from a Tab. Valid for the lifetime of | |
| 429 // the drag session. | |
| 430 scoped_ptr<DraggedTabController> drag_controller_; | |
| 431 | |
| 432 std::vector<TabData> tab_data_; | |
| 433 | |
| 434 // To ensure all tabs pulse at the same time they share the same animation | 369 // To ensure all tabs pulse at the same time they share the same animation |
| 435 // container. This is that animation container. | 370 // container. This is that animation container. |
| 436 scoped_refptr<AnimationContainer> animation_container_; | 371 scoped_refptr<AnimationContainer> animation_container_; |
| 437 | 372 |
| 438 views::BoundsAnimator bounds_animator_; | 373 views::BoundsAnimator bounds_animator_; |
| 439 | 374 |
| 440 // Used for stage 1 of new tab animation. | 375 // Used for stage 1 of new tab animation. |
| 441 base::OneShotTimer<TabStrip> new_tab_timer_; | 376 base::OneShotTimer<TabStrip> new_tab_timer_; |
| 442 | 377 |
| 443 // Set for special animations. | 378 // Set for special animations. |
| 444 AnimationType animation_type_; | 379 AnimationType animation_type_; |
| 445 | 380 |
| 446 // Whether the new tab button is being displayed. | 381 // Whether the new tab button is being displayed. |
| 447 bool new_tab_button_enabled_; | 382 bool new_tab_button_enabled_; |
| 448 | 383 |
| 449 // If true, we're cancelling the animation. | 384 // If true, we're cancelling the animation. |
| 450 bool cancelling_animation_; | 385 bool cancelling_animation_; |
| 451 | 386 |
| 452 // Used by DraggedTabController when inserting a tab into our model. | |
| 453 bool attaching_dragged_tab_; | |
| 454 | |
| 455 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 387 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
| 456 }; | 388 }; |
| 457 | 389 |
| 458 #endif // CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ | 390 #endif // CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_H_ |
| OLD | NEW |