bubble_frame_view.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/insets.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/bubble/bubble_border.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/window/non_client_view.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is a NonClientFrameView used to render the BubbleBorder. 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the border to |border|, taking ownership. Important: do not call 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set_border() directly to change the border, use SetBubbleBorder() instead. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BubbleFrameView(const gfx::Insets& margins, BubbleBorder* border); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~BubbleFrameView(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NonClientFrameView overrides: 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Rect GetWindowBoundsForClientBounds( 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& client_bounds) const OVERRIDE; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetWindowMask(const gfx::Size& size, 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Path* window_mask) OVERRIDE {} 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ResetWindowControls() OVERRIDE {} 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void UpdateWindowIcon() OVERRIDE {} 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void UpdateWindowTitle() OVERRIDE {} 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // View overrides: 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Size GetPreferredSize() OVERRIDE; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BubbleBorder* bubble_border() const { return bubble_border_; } 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Insets content_margins() const { return content_margins_; } 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Given the size of the contents and the rect to point at, returns the bounds 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the bubble window. The bubble's arrow location may change if the bubble 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // does not fit on the monitor and |adjust_if_offscreen| is true. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size client_size, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool adjust_if_offscreen); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBubbleBorder(BubbleBorder* border); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the bounds for the monitor showing the specified |rect|. 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This function is virtual to support testing environments. 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Mirrors the bubble's arrow location on the |vertical| or horizontal axis, 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the generated window bounds don't fit in the monitor bounds. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MirrorArrowIfOffScreen(bool vertical, 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& anchor_rect, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Size& client_size); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adjust the bubble's arrow offsets if the generated window bounds don't fit 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in the monitor bounds. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect, 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Size& client_size); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The bubble border. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BubbleBorder* bubble_border_; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Margins between the content and the inside of the border, in pixels. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Insets content_margins_; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 84