bubble_frame_view.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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
15namespace views {
16
17class Label;
18class LabelButton;
19class BubbleBorder;
20
21// The non-client frame view of bubble-styled widgets.
22class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
23                                     public ButtonListener {
24 public:
25  explicit BubbleFrameView(const gfx::Insets& content_margins);
26  virtual ~BubbleFrameView();
27
28  // NonClientFrameView overrides:
29  virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
30  virtual gfx::Rect GetWindowBoundsForClientBounds(
31      const gfx::Rect& client_bounds) const OVERRIDE;
32  virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
33  virtual void GetWindowMask(const gfx::Size& size,
34                             gfx::Path* window_mask) OVERRIDE;
35  virtual void ResetWindowControls() OVERRIDE;
36  virtual void UpdateWindowIcon() OVERRIDE;
37  virtual void UpdateWindowTitle() OVERRIDE;
38
39  // View overrides:
40  virtual gfx::Insets GetInsets() const OVERRIDE;
41  virtual gfx::Size GetPreferredSize() OVERRIDE;
42  virtual void Layout() OVERRIDE;
43  virtual std::string GetClassName() const OVERRIDE;
44
45  // Overridden from ButtonListener:
46  virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
47
48  // Use bubble_border() and SetBubbleBorder(), not border() and set_border().
49  BubbleBorder* bubble_border() const { return bubble_border_; }
50  void SetBubbleBorder(BubbleBorder* border);
51
52  gfx::Insets content_margins() const { return content_margins_; }
53
54  void SetTitle(const string16& title);
55  void SetShowCloseButton(bool show);
56  void SetTitlebarExtraView(View* view);
57
58  void set_can_drag(bool can_drag) { can_drag_ = can_drag; }
59
60  // Given the size of the contents and the rect to point at, returns the bounds
61  // of the bubble window. The bubble's arrow location may change if the bubble
62  // does not fit on the monitor and |adjust_if_offscreen| is true.
63  gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
64                                   gfx::Size client_size,
65                                   bool adjust_if_offscreen);
66
67 protected:
68  // Returns the bounds for the monitor showing the specified |rect|.
69  // This function is virtual to support testing environments.
70  virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect);
71
72 private:
73  FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView);
74
75  // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
76  // if the generated window bounds don't fit in the monitor bounds.
77  void MirrorArrowIfOffScreen(bool vertical,
78                              const gfx::Rect& anchor_rect,
79                              const gfx::Size& client_size);
80
81  // Adjust the bubble's arrow offsets if the generated window bounds don't fit
82  // in the monitor bounds.
83  void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect,
84                              const gfx::Size& client_size);
85
86  // The bubble border.
87  BubbleBorder* bubble_border_;
88
89  // Margins between the content and the inside of the border, in pixels.
90  gfx::Insets content_margins_;
91
92  // The optional title and (x) close button.
93  Label* title_;
94  LabelButton* close_;
95
96  // When supplied, this view is placed in the titlebar between the title and
97  // (x) close button.
98  View* titlebar_extra_view_;
99
100  // A flag controlling the ability to drag this frame.
101  bool can_drag_;
102
103  DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
104};
105
106}  // namespace views
107
108#endif  // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
109