diff options
Diffstat (limited to 'chrome/browser/views/info_bubble.h')
-rw-r--r-- | chrome/browser/views/info_bubble.h | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h index 90911b5..ea80b0f 100644 --- a/chrome/browser/views/info_bubble.h +++ b/chrome/browser/views/info_bubble.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "third_party/skia/include/core/SkColor.h" #include "views/accelerator.h" +#include "views/view.h" #if defined(OS_WIN) #include "views/widget/widget_win.h" #elif defined(OS_LINUX) @@ -23,6 +24,7 @@ // have any additional margins. class BorderWidget; +class BubbleBorder; class InfoBubble; namespace views { @@ -33,6 +35,46 @@ namespace gfx { class Path; } +// This is used to paint the border of the InfoBubble. Windows uses this via +// BorderWidget (see below), while others can use it directly in the bubble. +class BorderContents : public views::View { + public: + BorderContents() : bubble_border_(NULL) { } + + // Given the size of the contents and the rect to point at, initializes the + // bubble and returns the bounds of both the border + // and the contents inside the bubble. + // |prefer_arrow_on_right| specifies the preferred location for the arrow + // anchor. If the bubble does not fit on the monitor, the arrow location may + // changed so it can. + // + // TODO(pkasting): Maybe this should use mirroring transformations instead, + // which would hopefully simplify this code. + virtual void InitAndGetBounds( + const gfx::Rect& position_relative_to, // In screen coordinates + const gfx::Size& contents_size, + bool prefer_arrow_on_right, + gfx::Rect* contents_bounds, // Returned in window coordinates + gfx::Rect* window_bounds); // Returned in screen coordinates + + protected: + virtual ~BorderContents() { } + + // Margins between the contents and the inside of the border, in pixels. + static const int kLeftMargin = 6; + static const int kTopMargin = 6; + static const int kRightMargin = 6; + static const int kBottomMargin = 9; + + BubbleBorder* bubble_border_; + + private: + // Overridden from View: + virtual void Paint(gfx::Canvas* canvas); + + DISALLOW_COPY_AND_ASSIGN(BorderContents); +}; + #if defined(OS_WIN) // This is a window that surrounds the info bubble and paints the margin and // border. It is a separate window so that it can be a layered window, so that @@ -47,12 +89,15 @@ class BorderWidget : public views::WidgetWin { // Given the owning (parent) window, the size of the contained contents // (without margins), and the rect (in screen coordinates) to point to, // initializes the window and returns the bounds (in screen coordinates) the - // contents should use. |is_rtl| is supplied to + // contents should use. |is_rtl| is supplied to // BorderContents::InitAndGetBounds(), see its declaration for details. - gfx::Rect InitAndGetBounds(HWND owner, - const gfx::Rect& position_relative_to, - const gfx::Size& contents_size, - bool is_rtl); + virtual gfx::Rect InitAndGetBounds(HWND owner, + const gfx::Rect& position_relative_to, + const gfx::Size& contents_size, + bool is_rtl); + + protected: + BorderContents* border_contents_; private: // Overridden from WidgetWin: @@ -82,7 +127,7 @@ class InfoBubbleDelegate { virtual bool PreferOriginSideAnchor() { return true; } }; -// TODO: this code is ifdef-tastic. It might be cleaner to refactor the +// TODO(sky): this code is ifdef-tastic. It might be cleaner to refactor the // WidgetFoo subclass into a separate class that calls into InfoBubble. // That way InfoBubble has no (or very few) ifdefs. class InfoBubble @@ -120,10 +165,10 @@ class InfoBubble virtual ~InfoBubble() {} // Creates the InfoBubble. - void Init(views::Window* parent, - const gfx::Rect& position_relative_to, - views::View* contents, - InfoBubbleDelegate* delegate); + virtual void Init(views::Window* parent, + const gfx::Rect& position_relative_to, + views::View* contents, + InfoBubbleDelegate* delegate); #if defined(OS_WIN) // Overridden from WidgetWin: @@ -133,6 +178,11 @@ class InfoBubble virtual void IsActiveChanged(); #endif +#if defined(OS_WIN) + // The window used to render the padding, border and arrow. + scoped_ptr<BorderWidget> border_; +#endif + private: // Closes the window notifying the delegate. |closed_by_escape| is true if // the close is the result of pressing escape. @@ -147,11 +197,6 @@ class InfoBubble // The window that this InfoBubble is parented to. views::Window* parent_; -#if defined(OS_WIN) - // The window used to render the padding, border and arrow. - scoped_ptr<BorderWidget> border_; -#endif - // Have we been closed? bool closed_; |