1 // Copyright 2019 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_VIEWS_TABS_TAB_ANIMATION_STATE_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_ANIMATION_STATE_H_ 7 8 #include <vector> 9 #include "chrome/browser/ui/tabs/tab_types.h" 10 11 // Contains the data necessary to determine the bounds of a tab even while 12 // it's in the middle of animating between states. Immutable (except for 13 // replacement via assignment). 14 class TabAnimationState { 15 public: 16 // Returns the TabAnimationState that expresses the provided 17 // ideal tab state. These correspond to the endpoints of animations. 18 // |open| controls whether the returned TabAnimationState is fully open or 19 // closed. |pinned| and |active| are analogous. |tab_index_offset| is the 20 // distance, in tab indices, away from its current model position the tab 21 // should be drawn at. It may be negative. 22 static TabAnimationState ForIdealTabState(TabOpen open, 23 TabPinned pinned, 24 TabActive active, 25 int tab_index_offset); 26 27 // Interpolates from |origin| to |target| by |value|. 28 // |value| should be in the [0, 1] interval, where 0 29 // corresponds to |origin| and 1 to |target|. 30 static TabAnimationState Interpolate(float value, 31 TabAnimationState origin, 32 TabAnimationState target); 33 openness()34 float openness() const { return openness_; } pinnedness()35 float pinnedness() const { return pinnedness_; } activeness()36 float activeness() const { return activeness_; } 37 38 TabAnimationState WithOpen(TabOpen open) const; 39 TabAnimationState WithPinned(TabPinned pinned) const; 40 TabAnimationState WithActive(TabActive active) const; 41 42 int GetLeadingEdgeOffset(std::vector<int> tab_widths, int my_index) const; 43 44 bool IsFullyClosed() const; 45 46 private: TabAnimationState(float openness,float pinnedness,float activeness,float normalized_leading_edge_x)47 TabAnimationState(float openness, 48 float pinnedness, 49 float activeness, 50 float normalized_leading_edge_x) 51 : openness_(openness), 52 pinnedness_(pinnedness), 53 activeness_(activeness), 54 normalized_leading_edge_x_(normalized_leading_edge_x) {} 55 56 // The degree to which the tab is open. 1 if it is, 0 if it is not, and in 57 // between if it's in the process of animating between open and closed. 58 float openness_; 59 60 // The degree to which the tab is pinned. 1 if it is, 0 if it is not, and in 61 // between if it's in the process of animating between pinned and unpinned. 62 float pinnedness_; 63 64 // The degree to which the tab is active. 1 if it is, 0 if it is not, and in 65 // between if it's in the process of animating between active and inactive. 66 float activeness_; 67 68 // The offset, in number of tab slots, of the tab's bounds relative to the 69 // space dedicated for it in the tabstrip. 70 float normalized_leading_edge_x_; 71 }; 72 73 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_ANIMATION_STATE_H_ 74