Home | History | Annotate | Download | only in bubble
      1 // Copyright (c) 2012 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 UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
      6 #define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/gtest_prod_util.h"
     11 #include "ui/gfx/insets.h"
     12 #include "ui/views/controls/button/button.h"
     13 #include "ui/views/window/non_client_view.h"
     14 
     15 namespace views {
     16 
     17 class Label;
     18 class LabelButton;
     19 class BubbleBorder;
     20 
     21 // The non-client frame view of bubble-styled widgets.
     22 class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
     23                                      public ButtonListener {
     24  public:
     25   // Internal class name.
     26   static const char kViewClassName[];
     27 
     28   // Insets to make bubble contents align horizontal with the bubble title.
     29   // NOTE: this does not take into account whether a title actually exists.
     30   static gfx::Insets GetTitleInsets();
     31 
     32   explicit BubbleFrameView(const gfx::Insets& content_margins);
     33   virtual ~BubbleFrameView();
     34 
     35   // NonClientFrameView overrides:
     36   virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
     37   virtual gfx::Rect GetWindowBoundsForClientBounds(
     38       const gfx::Rect& client_bounds) const OVERRIDE;
     39   virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
     40   virtual void GetWindowMask(const gfx::Size& size,
     41                              gfx::Path* window_mask) OVERRIDE;
     42   virtual void ResetWindowControls() OVERRIDE;
     43   virtual void UpdateWindowIcon() OVERRIDE;
     44   virtual void UpdateWindowTitle() OVERRIDE;
     45 
     46   // View overrides:
     47   virtual gfx::Insets GetInsets() const OVERRIDE;
     48   virtual gfx::Size GetPreferredSize() OVERRIDE;
     49   virtual void Layout() OVERRIDE;
     50   virtual const char* GetClassName() const OVERRIDE;
     51   virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
     52 
     53   // Overridden from ButtonListener:
     54   virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
     55 
     56   // Use bubble_border() and SetBubbleBorder(), not border() and set_border().
     57   BubbleBorder* bubble_border() const { return bubble_border_; }
     58   void SetBubbleBorder(BubbleBorder* border);
     59 
     60   gfx::Insets content_margins() const { return content_margins_; }
     61 
     62   void SetTitlebarExtraView(View* view);
     63 
     64   // Given the size of the contents and the rect to point at, returns the bounds
     65   // of the bubble window. The bubble's arrow location may change if the bubble
     66   // does not fit on the monitor and |adjust_if_offscreen| is true.
     67   gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
     68                                    gfx::Size client_size,
     69                                    bool adjust_if_offscreen);
     70 
     71  protected:
     72   // Returns the bounds for the monitor showing the specified |rect|.
     73   // This function is virtual to support testing environments.
     74   virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect);
     75 
     76  private:
     77   FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView);
     78 
     79   // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
     80   // if the generated window bounds don't fit in the monitor bounds.
     81   void MirrorArrowIfOffScreen(bool vertical,
     82                               const gfx::Rect& anchor_rect,
     83                               const gfx::Size& client_size);
     84 
     85   // Adjust the bubble's arrow offsets if the generated window bounds don't fit
     86   // in the monitor bounds.
     87   void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect,
     88                               const gfx::Size& client_size);
     89 
     90   // The bubble border.
     91   BubbleBorder* bubble_border_;
     92 
     93   // Margins between the content and the inside of the border, in pixels.
     94   gfx::Insets content_margins_;
     95 
     96   // The optional title and (x) close button.
     97   Label* title_;
     98   LabelButton* close_;
     99 
    100   // When supplied, this view is placed in the titlebar between the title and
    101   // (x) close button.
    102   View* titlebar_extra_view_;
    103 
    104   DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
    105 };
    106 
    107 }  // namespace views
    108 
    109 #endif  // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
    110