Home | History | Annotate | Download | only in bubble
      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_VIEWS_BUBBLE_BORDER_CONTENTS_H_
      6 #define CHROME_BROWSER_UI_VIEWS_BUBBLE_BORDER_CONTENTS_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/ui/views/bubble/bubble_border.h"
     10 #include "third_party/skia/include/core/SkColor.h"
     11 #include "views/view.h"
     12 
     13 // This is used to paint the border of the Bubble. Windows uses this via
     14 // BorderWidgetWin, while others can use it directly in the bubble.
     15 class BorderContents : public views::View {
     16  public:
     17   BorderContents() : bubble_border_(NULL) { }
     18 
     19   // Must be called before this object can be used.
     20   void Init();
     21 
     22   // Sets the background color.
     23   void SetBackgroundColor(SkColor color);
     24 
     25   // Given the size of the contents and the rect to point at, returns the bounds
     26   // of both the border and the contents inside the bubble.
     27   // |arrow_location| specifies the preferred location for the arrow
     28   // anchor. If the bubble does not fit on the monitor and
     29   // |allow_bubble_offscreen| is false, the arrow location may change so the
     30   // bubble shows entirely.
     31   virtual void SizeAndGetBounds(
     32       const gfx::Rect& position_relative_to,  // In screen coordinates
     33       BubbleBorder::ArrowLocation arrow_location,
     34       bool allow_bubble_offscreen,
     35       const gfx::Size& contents_size,
     36       gfx::Rect* contents_bounds,             // Returned in window coordinates
     37       gfx::Rect* window_bounds);              // Returned in screen coordinates
     38 
     39  protected:
     40   virtual ~BorderContents() { }
     41 
     42   // Returns the bounds for the monitor showing the specified |rect|.
     43   // Overridden in unit-tests.
     44   virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect);
     45 
     46   // Margins between the contents and the inside of the border, in pixels.
     47   static const int kLeftMargin = 6;
     48   static const int kTopMargin = 6;
     49   static const int kRightMargin = 6;
     50   static const int kBottomMargin = 9;
     51 
     52   BubbleBorder* bubble_border_;
     53 
     54  private:
     55   // Changes |arrow_location| to its mirrored version, vertically if |vertical|
     56   // is true, horizontally otherwise, if |window_bounds| don't fit in
     57   // |monitor_bounds|.
     58   void MirrorArrowIfOffScreen(bool vertical,
     59                               const gfx::Rect& position_relative_to,
     60                               const gfx::Rect& monitor_bounds,
     61                               const gfx::Size& local_contents_size,
     62                               BubbleBorder::ArrowLocation* arrow_location,
     63                               gfx::Rect* window_bounds);
     64 
     65   // Computes how much |window_bounds| is off-screen of the monitor bounds
     66   // |monitor_bounds| and puts the values in |offscreen_insets|.
     67   // Returns false if |window_bounds| is actually contained in |monitor_bounds|,
     68   // in which case |offscreen_insets| is not modified.
     69   static bool ComputeOffScreenInsets(const gfx::Rect& monitor_bounds,
     70                                      const gfx::Rect& window_bounds,
     71                                      gfx::Insets* offscreen_insets);
     72 
     73   // Convenience method that returns the height of |insets| if |vertical| is
     74   // true, its width otherwise.
     75   static int GetInsetsLength(const gfx::Insets& insets, bool vertical);
     76 
     77   DISALLOW_COPY_AND_ASSIGN(BorderContents);
     78 };
     79 
     80 #endif  // CHROME_BROWSER_UI_VIEWS_BUBBLE_BORDER_CONTENTS_H_
     81