tab.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/tabs/tab_renderer_data.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/layout.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/point.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/context_menu_controller.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/button/button.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/glow_hover_controller.h" 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/views/view.h" 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class TabController; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Animation; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AnimationContainer; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LinearAnimation; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MultiAnimation; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImageButton; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Label; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/////////////////////////////////////////////////////////////////////////////// 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A View that renders a Tab in a TabStrip. 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/////////////////////////////////////////////////////////////////////////////// 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Tab : public gfx::AnimationDelegate, 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::ButtonListener, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::ContextMenuController, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::View { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The menu button's class name. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char kViewClassName[]; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Tab(TabController* controller); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Tab(); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used to set/check whether this Tab is being animated closed. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_closing(bool closing) { closing_ = closing; } 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool closing() const { return closing_; } 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // See description above field. 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_dragging(bool dragging) { dragging_ = dragging; } 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool dragging() const { return dragging_; } 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the container all animations run from. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_animation_container(gfx::AnimationContainer* container); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns true if this tab is the active tab. 63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool IsActive() const; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the tab is selected. 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool IsSelected() const; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the data this tabs displays. Invokes DataChanged. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetData(const TabRendererData& data); 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TabRendererData& data() const { return data_; } 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the network state. If the network state changes NetworkStateChanged is 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // invoked. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateLoadingAnimation(TabRendererData::NetworkState state); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Starts/Stops a pulse animation. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartPulse(); 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StopPulse(); 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Start/stop the mini-tab title animation. 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StartMiniTabTitleAnimation(); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StopMiniTabTitleAnimation(); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the background offset used to match the image in the inactive tab 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to the frame image. 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void set_background_offset(const gfx::Point& offset) { 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) background_offset_ = offset; 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this tab became the active tab selected in 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response to the last ui::ET_GESTURE_BEGIN gesture dispatched to 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this tab. Only used for collecting UMA metrics. 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See ash/touch/touch_uma.cc. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool tab_activated_with_last_gesture_begin() const { 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return tab_activated_with_last_gesture_begin_; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::GlowHoverController* hover_controller() { 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return &hover_controller_; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the inset within the first dragged tab to use when calculating the 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // "drag insertion point". If we simply used the x-coordinate of the tab, 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // we'd be calculating based on a point well before where the user considers 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the tab to "be". The value here is chosen to "feel good" based on the 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // widths of the tab images and the tab overlap. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this must return a value smaller than the midpoint of any tab's 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // width, or else the user won't be able to drag a tab to the left of the 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first tab in the strip. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int leading_width_for_drag() { return 16; } 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the minimum possible size of a single unselected Tab. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static gfx::Size GetMinimumUnselectedSize(); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the minimum possible size of a selected Tab. Selected tabs must 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // always show a close button and have a larger minimum size than unselected 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tabs. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static gfx::Size GetMinimumSelectedSize(); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the preferred size of a single Tab, assuming space is 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // available. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static gfx::Size GetStandardSize(); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Returns the width for touch tabs. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int GetTouchWidth(); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the width for mini-tabs. Mini-tabs always have this width. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int GetMiniWidth(); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the height for immersive mode tabs. 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static int GetImmersiveHeight(); 1310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class TabTest; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(TabTest, CloseButtonLayout); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class TabStripTest; 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabHitTestMaskWhenStacked); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(TabStripTest, ClippedTabCloseButton); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The animation object used to swap the favicon with the sad tab icon. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class FaviconCrashAnimation; 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class TabCloseButton; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Contains a cached image and the values used to generate it. 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct ImageCacheEntry { 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ImageCacheEntry(); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ImageCacheEntry(); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ID of the resource used. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int resource_id; 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Scale factor we're drawing it. 1537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ui::ScaleFactor scale_factor; 1547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // The image. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::ImageSkia image; 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::list<ImageCacheEntry> ImageCache; 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from gfx::AnimationDelegate: 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::ButtonListener: 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ButtonPressed(views::Button* sender, 16858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const ui::Event& event) OVERRIDE; 16958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 17058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Overridden from views::ContextMenuController: 17158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void ShowContextMenuForView(views::View* source, 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& point, 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::MenuSourceType source_type) OVERRIDE; 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::View: 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Layout() OVERRIDE; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnThemeChanged() OVERRIDE; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual const char* GetClassName() const OVERRIDE; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HasHitTestMask() const OVERRIDE; 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetHitTestMask(HitTestSource source, 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Path* path) const OVERRIDE; 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool GetTooltipText(const gfx::Point& p, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::string16* tooltip) const OVERRIDE; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool GetTooltipTextOrigin(const gfx::Point& p, 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point* origin) const OVERRIDE; 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseCaptureLost() OVERRIDE; 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from ui::EventHandler: 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked from Layout to adjust the position of the favicon or media 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // indicator for mini tabs. 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const; 202 203 // Invoked from SetData after |data_| has been updated to the new data. 204 void DataChanged(const TabRendererData& old); 205 206 // Paint with the normal tab style. 207 void PaintTab(gfx::Canvas* canvas); 208 209 // Paint with the "immersive mode" light-bar style. 210 void PaintImmersiveTab(gfx::Canvas* canvas); 211 212 // Paint various portions of the Tab 213 void PaintTabBackground(gfx::Canvas* canvas); 214 void PaintInactiveTabBackgroundWithTitleChange( 215 gfx::Canvas* canvas, 216 gfx::MultiAnimation* animation); 217 void PaintInactiveTabBackground(gfx::Canvas* canvas); 218 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, 219 int tab_id); 220 void PaintActiveTabBackground(gfx::Canvas* canvas); 221 222 // Paints the favicon and media indicator icon, mirrored for RTL if needed. 223 void PaintIcon(gfx::Canvas* canvas); 224 void PaintMediaIndicator(gfx::Canvas* canvas); 225 226 // Invoked if data_.network_state changes, or the network_state is not none. 227 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, 228 TabRendererData::NetworkState state); 229 230 // Returns the number of favicon-size elements that can fit in the tab's 231 // current size. 232 int IconCapacity() const; 233 234 // Returns whether the Tab should display a favicon. 235 bool ShouldShowIcon() const; 236 237 // Returns whether the Tab should display the media indicator. 238 bool ShouldShowMediaIndicator() const; 239 240 // Returns whether the Tab should display a close button. 241 bool ShouldShowCloseBox() const; 242 243 // Gets the throb value for the tab. When a tab is not selected the 244 // active background is drawn at |GetThrobValue()|%. This is used for hover, 245 // mini tab title change and pulsing. 246 double GetThrobValue(); 247 248 // Set the temporary offset for the favicon. This is used during the crash 249 // animation. 250 void SetFaviconHidingOffset(int offset); 251 252 void DisplayCrashedFavicon(); 253 void ResetCrashedFavicon(); 254 255 void StopCrashAnimation(); 256 void StartCrashAnimation(); 257 258 // Returns true if the crash animation is currently running. 259 bool IsPerformingCrashAnimation() const; 260 261 // Starts the media indicator fade-in/out animation. There's no stop method 262 // because this is not a continuous animation. 263 void StartMediaIndicatorAnimation(); 264 265 // Schedules repaint task for icon. 266 void ScheduleIconPaint(); 267 268 // Returns the rectangle for the light bar in immersive mode. 269 gfx::Rect GetImmersiveBarRect() const; 270 271 // Gets the tab id and frame id. 272 void GetTabIdAndFrameId(views::Widget* widget, 273 int* tab_id, 274 int* frame_id) const; 275 276 // Performs a one-time initialization of static resources such as tab images. 277 static void InitTabResources(); 278 279 // Returns the minimum possible size of a single unselected Tab, not 280 // including considering touch mode. 281 static gfx::Size GetBasicMinimumUnselectedSize(); 282 283 // Loads the images to be used for the tab background. 284 static void LoadTabImages(); 285 286 // Returns the cached image for the specified arguments, or an empty image if 287 // there isn't one cached. 288 static gfx::ImageSkia GetCachedImage(int resource_id, 289 const gfx::Size& size, 290 ui::ScaleFactor scale_factor); 291 292 // Caches the specified image. 293 static void SetCachedImage(int resource_id, 294 ui::ScaleFactor scale_factor, 295 const gfx::ImageSkia& image); 296 297 // The controller, never NULL. 298 TabController* controller_; 299 300 TabRendererData data_; 301 302 // True if the tab is being animated closed. 303 bool closing_; 304 305 // True if the tab is being dragged. 306 bool dragging_; 307 308 // The offset used to animate the favicon location. This is used when the tab 309 // crashes. 310 int favicon_hiding_offset_; 311 312 // The current index of the loading animation. The range varies depending on 313 // whether the tab is loading or waiting, see AdvanceLoadingAnimation(). 314 int loading_animation_frame_; 315 316 // Step in the immersive loading progress indicator. 317 int immersive_loading_step_; 318 319 bool should_display_crashed_favicon_; 320 321 // Whole-tab throbbing "pulse" animation. 322 scoped_ptr<gfx::Animation> tab_animation_; 323 324 // Crash icon animation (in place of favicon). 325 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; 326 327 // Media indicator fade-in/out animation (i.e., only on show/hide, not a 328 // continuous animation). 329 scoped_ptr<gfx::Animation> media_indicator_animation_; 330 TabMediaState animating_media_state_; 331 332 scoped_refptr<gfx::AnimationContainer> animation_container_; 333 334 views::ImageButton* close_button_; 335 views::Label* title_; 336 337 bool tab_activated_with_last_gesture_begin_; 338 339 views::GlowHoverController hover_controller_; 340 341 // The bounds of various sections of the display. 342 gfx::Rect favicon_bounds_; 343 gfx::Rect media_indicator_bounds_; 344 345 // The offset used to paint the inactive background image. 346 gfx::Point background_offset_; 347 348 struct TabImage { 349 gfx::ImageSkia* image_l; 350 gfx::ImageSkia* image_c; 351 gfx::ImageSkia* image_r; 352 int l_width; 353 int r_width; 354 }; 355 static TabImage tab_active_; 356 static TabImage tab_inactive_; 357 static TabImage tab_alpha_; 358 359 // Whether we're showing the icon. It is cached so that we can detect when it 360 // changes and layout appropriately. 361 bool showing_icon_; 362 363 // Whether we're showing the media indicator. It is cached so that we can 364 // detect when it changes and layout appropriately. 365 bool showing_media_indicator_; 366 367 // Whether we are showing the close button. It is cached so that we can 368 // detect when it changes and layout appropriately. 369 bool showing_close_button_; 370 371 // The current color of the close button. 372 SkColor close_button_color_; 373 374 // As the majority of the tabs are inactive, and painting tabs is slowish, 375 // we cache a handful of the inactive tab backgrounds here. 376 static ImageCache* image_cache_; 377 378 DISALLOW_COPY_AND_ASSIGN(Tab); 379}; 380 381#endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 382