bubble_frame_view.h revision a36e5920737c6adbddd3e43b760e5de8431db6e0
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  // Internal class name.
26  static const char kViewClassName[];
27
28  explicit BubbleFrameView(const gfx::Insets& content_margins);
29  virtual ~BubbleFrameView();
30
31  // NonClientFrameView overrides:
32  virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
33  virtual gfx::Rect GetWindowBoundsForClientBounds(
34      const gfx::Rect& client_bounds) const OVERRIDE;
35  virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
36  virtual void GetWindowMask(const gfx::Size& size,
37                             gfx::Path* window_mask) OVERRIDE;
38  virtual void ResetWindowControls() OVERRIDE;
39  virtual void UpdateWindowIcon() OVERRIDE;
40  virtual void UpdateWindowTitle() OVERRIDE;
41
42  // View overrides:
43  virtual gfx::Insets GetInsets() const OVERRIDE;
44  virtual gfx::Size GetPreferredSize() OVERRIDE;
45  virtual void Layout() OVERRIDE;
46  virtual const char* GetClassName() const OVERRIDE;
47  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
48
49  // Overridden from ButtonListener:
50  virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
51
52  // Use bubble_border() and SetBubbleBorder(), not border() and set_border().
53  BubbleBorder* bubble_border() const { return bubble_border_; }
54  void SetBubbleBorder(BubbleBorder* border);
55
56  gfx::Insets content_margins() const { return content_margins_; }
57
58  void SetTitlebarExtraView(View* view);
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  DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
101};
102
103}  // namespace views
104
105#endif  // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
106