1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Use of this source code is governed by a BSD-style license that can be 3ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// found in the LICENSE file. 4ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 5ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#ifndef CHROME_BROWSER_UI_VIEWS_BUBBLE_BORDER_CONTENTS_H_ 6ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#define CHROME_BROWSER_UI_VIEWS_BUBBLE_BORDER_CONTENTS_H_ 7ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#pragma once 8ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 9ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "chrome/browser/ui/views/bubble/bubble_border.h" 10ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "third_party/skia/include/core/SkColor.h" 11ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "views/view.h" 12ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 13ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// This is used to paint the border of the Bubble. Windows uses this via 14ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// BorderWidgetWin, while others can use it directly in the bubble. 15ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsenclass BorderContents : public views::View { 16ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen public: 17ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen BorderContents() : bubble_border_(NULL) { } 18ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 19ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Must be called before this object can be used. 20ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen void Init(); 21ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 22ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Sets the background color. 23ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen void SetBackgroundColor(SkColor color); 24ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 25ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Given the size of the contents and the rect to point at, returns the bounds 26ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // of both the border and the contents inside the bubble. 27ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // |arrow_location| specifies the preferred location for the arrow 28ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // anchor. If the bubble does not fit on the monitor and 29ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // |allow_bubble_offscreen| is false, the arrow location may change so the 30ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // bubble shows entirely. 31ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual void SizeAndGetBounds( 32ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Rect& position_relative_to, // In screen coordinates 33ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen BubbleBorder::ArrowLocation arrow_location, 34ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen bool allow_bubble_offscreen, 35ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Size& contents_size, 36ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen gfx::Rect* contents_bounds, // Returned in window coordinates 37ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen gfx::Rect* window_bounds); // Returned in screen coordinates 38ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 39ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen protected: 40ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual ~BorderContents() { } 41ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 42ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Returns the bounds for the monitor showing the specified |rect|. 43ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Overridden in unit-tests. 44ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect); 45ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 46ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Margins between the contents and the inside of the border, in pixels. 47ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static const int kLeftMargin = 6; 48ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static const int kTopMargin = 6; 49ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static const int kRightMargin = 6; 50ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static const int kBottomMargin = 9; 51ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 52ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen BubbleBorder* bubble_border_; 53ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 54ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen private: 55ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Changes |arrow_location| to its mirrored version, vertically if |vertical| 56ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // is true, horizontally otherwise, if |window_bounds| don't fit in 57ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // |monitor_bounds|. 58ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen void MirrorArrowIfOffScreen(bool vertical, 59ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Rect& position_relative_to, 60ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Rect& monitor_bounds, 61ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Size& local_contents_size, 62ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen BubbleBorder::ArrowLocation* arrow_location, 63ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen gfx::Rect* window_bounds); 64ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 65ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Computes how much |window_bounds| is off-screen of the monitor bounds 66ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // |monitor_bounds| and puts the values in |offscreen_insets|. 67ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Returns false if |window_bounds| is actually contained in |monitor_bounds|, 68ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // in which case |offscreen_insets| is not modified. 69ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static bool ComputeOffScreenInsets(const gfx::Rect& monitor_bounds, 70ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const gfx::Rect& window_bounds, 71ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen gfx::Insets* offscreen_insets); 72ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 73ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Convenience method that returns the height of |insets| if |vertical| is 74ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // true, its width otherwise. 75ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen static int GetInsetsLength(const gfx::Insets& insets, bool vertical); 76ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 77ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen DISALLOW_COPY_AND_ASSIGN(BorderContents); 78ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen}; 79ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 80ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#endif // CHROME_BROWSER_UI_VIEWS_BUBBLE_BORDER_CONTENTS_H_ 81