bubble_frame_view.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 "third_party/skia/include/core/SkColor.h"
12#include "ui/gfx/insets.h"
13#include "ui/views/bubble/bubble_border.h"
14#include "ui/views/window/non_client_view.h"
15
16namespace views {
17
18// This is a NonClientFrameView used to render the BubbleBorder.
19class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView {
20 public:
21  // Sets the border to |border|, taking ownership. Important: do not call
22  // set_border() directly to change the border, use SetBubbleBorder() instead.
23  BubbleFrameView(const gfx::Insets& margins, BubbleBorder* border);
24  virtual ~BubbleFrameView();
25
26  // NonClientFrameView overrides:
27  virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
28  virtual gfx::Rect GetWindowBoundsForClientBounds(
29      const gfx::Rect& client_bounds) const OVERRIDE;
30  virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
31  virtual void GetWindowMask(const gfx::Size& size,
32                             gfx::Path* window_mask) OVERRIDE {}
33  virtual void ResetWindowControls() OVERRIDE {}
34  virtual void UpdateWindowIcon() OVERRIDE {}
35  virtual void UpdateWindowTitle() OVERRIDE {}
36
37  // View overrides:
38  virtual gfx::Size GetPreferredSize() OVERRIDE;
39
40  BubbleBorder* bubble_border() const { return bubble_border_; }
41
42  gfx::Insets content_margins() const { return content_margins_; }
43
44  // Given the size of the contents and the rect to point at, returns the bounds
45  // of the bubble window. The bubble's arrow location may change if the bubble
46  // does not fit on the monitor and |adjust_if_offscreen| is true.
47  gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
48                                   gfx::Size client_size,
49                                   bool adjust_if_offscreen);
50
51  void SetBubbleBorder(BubbleBorder* border);
52
53 protected:
54  // Returns the bounds for the monitor showing the specified |rect|.
55  // This function is virtual to support testing environments.
56  virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect);
57
58 private:
59  FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView);
60
61  // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
62  // if the generated window bounds don't fit in the monitor bounds.
63  void MirrorArrowIfOffScreen(bool vertical,
64                              const gfx::Rect& anchor_rect,
65                              const gfx::Size& client_size);
66
67  // Adjust the bubble's arrow offsets if the generated window bounds don't fit
68  // in the monitor bounds.
69  void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect,
70                              const gfx::Size& client_size);
71
72  // The bubble border.
73  BubbleBorder* bubble_border_;
74
75  // Margins between the content and the inside of the border, in pixels.
76  gfx::Insets content_margins_;
77
78  DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
79};
80
81}  // namespace views
82
83#endif  // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
84