Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 2011 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_TOUCH_TABS_TOUCH_TAB_H_
      6 #define CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/memory/scoped_ptr.h"
     12 #include "chrome/browser/ui/views/tabs/base_tab.h"
     13 #include "ui/gfx/point.h"
     14 
     15 ///////////////////////////////////////////////////////////////////////////////
     16 //
     17 // TouchTab
     18 //
     19 //  A View that renders a TouchTab in a TouchTabStrip
     20 //
     21 // TODO(wyck): Use transformable views for scrolling.
     22 ///////////////////////////////////////////////////////////////////////////////
     23 class TouchTab : public BaseTab {
     24  public:
     25   // The menu button's class name.
     26   static const char kViewClassName[];
     27 
     28   explicit TouchTab(TabController* controller);
     29   virtual ~TouchTab();
     30 
     31   // Set the background offset used to match the image in the inactive tab
     32   // to the frame image.
     33   void set_background_offset(const gfx::Point& offset) {
     34     background_offset_ = offset;
     35   }
     36 
     37   // Returns the minimum possible size of a single unselected Tab.
     38   static gfx::Size GetMinimumUnselectedSize();
     39 
     40  protected:
     41   virtual const gfx::Rect& GetTitleBounds() const;
     42   virtual const gfx::Rect& GetIconBounds() const;
     43 
     44  private:
     45   // Overridden from views::View:
     46   virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
     47   virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
     48   virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
     49   virtual void OnPaint(gfx::Canvas* canvas);
     50   virtual void Layout();
     51   virtual bool HasHitTestMask() const;
     52   virtual void GetHitTestMask(gfx::Path* path) const;
     53 
     54   // Paint various portions of the Tab
     55   void PaintTabBackground(gfx::Canvas* canvas);
     56   void PaintIcon(gfx::Canvas* canvas);
     57   void PaintActiveTabBackground(gfx::Canvas* canvas);
     58 
     59   // TODO(wyck): will eventually add OnTouchEvent when the Touch Tab Strip
     60   // requires touch-specific event handling.
     61 
     62   // Performs a one-time initialization of static resources such as tab images.
     63   static void InitTabResources();
     64 
     65   // Loads the images to be used for the tab background.
     66   static void LoadTabImages();
     67 
     68   // the bounds of the title text
     69   gfx::Rect title_bounds_;
     70 
     71   // the bounds of the favicon
     72   gfx::Rect favicon_bounds_;
     73 
     74   // The offset used to paint the inactive background image.
     75   gfx::Point background_offset_;
     76 
     77   // 'l' is for left
     78   // 'c' is for center
     79   // 'r' is for right
     80   struct TouchTabImage {
     81     SkBitmap* image_l;
     82     SkBitmap* image_c;
     83     SkBitmap* image_r;
     84     int l_width;
     85     int r_width;
     86     int y_offset;
     87   };
     88   static TouchTabImage tab_active;
     89   static TouchTabImage tab_inactive;
     90   static TouchTabImage tab_alpha;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(TouchTab);
     93 };
     94 
     95 #endif  // CHROME_BROWSER_UI_TOUCH_TABS_TOUCH_TAB_H_
     96