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_TRAY_BUBBLE_VIEW_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/bubble/bubble_delegate.h" 103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/views/mouse_watcher.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/views_export.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Specialized bubble view for bubbles associated with a tray icon (e.g. the 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Ash status area). Mostly this handles custom anchor location and arrow and 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// border rendering. This also has its own delegate for handling mouse events 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and other implementation specific details. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LocatedEvent; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class View; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Widget; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TrayBubbleBorder; 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TrayBubbleContentMask; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class VIEWS_EXPORT TrayBubbleView : public views::BubbleDelegateView, 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public views::MouseWatcherListener { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // AnchorType differentiates between bubbles that are anchored on a tray 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // element (ANCHOR_TYPE_TRAY) and display an arrow, or that are floating on 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the screen away from the tray (ANCHOR_TYPE_BUBBLE). 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum AnchorType { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ANCHOR_TYPE_TRAY, 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ANCHOR_TYPE_BUBBLE, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // AnchorAlignment determines to which side of the anchor the bubble will 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // align itself. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum AnchorAlignment { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ANCHOR_ALIGNMENT_BOTTOM, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ANCHOR_ALIGNMENT_LEFT, 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ANCHOR_ALIGNMENT_RIGHT, 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ANCHOR_ALIGNMENT_TOP 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class VIEWS_EXPORT Delegate { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef TrayBubbleView::AnchorType AnchorType; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef TrayBubbleView::AnchorAlignment AnchorAlignment; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate() {} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Delegate() {} 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the view is destroyed. Any pointers to the view should be 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cleared when this gets called. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void BubbleViewDestroyed() = 0; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the mouse enters/exits the view. 673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Note: This event will only be called if the mouse gets actively moved by 683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // the user to enter the view. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnMouseEnteredView() = 0; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnMouseExitedView() = 0; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called from GetAccessibleState(); should return the appropriate 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // accessible name for the bubble. 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual base::string16 GetAccessibleNameForBubble() = 0; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Passes responsibility for BubbleDelegateView::GetAnchorRect to the 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // delegate. 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Rect GetAnchorRect( 79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::Widget* anchor_widget, 80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AnchorType anchor_type, 81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AnchorAlignment anchor_alignment) const = 0; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when a bubble wants to hide/destroy itself (e.g. last visible 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // child view was closed). 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HideBubble(const TrayBubbleView* bubble_view) = 0; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(Delegate); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct VIEWS_EXPORT InitParams { 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const int kArrowDefaultOffset; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitParams(AnchorType anchor_type, 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AnchorAlignment anchor_alignment, 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int min_width, 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int max_width); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AnchorType anchor_type; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AnchorAlignment anchor_alignment; 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int min_width; 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int max_width; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int max_height; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool can_activate; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool close_on_deactivate; 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor arrow_color; 106bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch bool first_item_has_no_margin; 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) views::BubbleBorder::Arrow arrow; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int arrow_offset; 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) views::BubbleBorder::ArrowPaintType arrow_paint_type; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::BubbleBorder::Shadow shadow; 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) views::BubbleBorder::BubbleAlignment arrow_alignment; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Constructs and returns a TrayBubbleView. init_params may be modified. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static TrayBubbleView* Create(gfx::NativeView parent_window, 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::View* anchor, 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate, 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitParams* init_params); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~TrayBubbleView(); 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets up animations, and show the bubble. Must occur after CreateBubble() 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is called. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void InitializeAndShowBubble(); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called whenever the bubble size or location may have changed. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateBubble(); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the maximum bubble height and resizes the bubble. 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetMaxHeight(int height); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the bubble width. 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetWidth(int width); 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets whether or not to paint the bubble border arrow. 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetArrowPaintType(views::BubbleBorder::ArrowPaintType arrow_paint_type); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the border insets. Called by TrayEventFilter. 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets GetBorderInsets() const; 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the delegate is destroyed. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void reset_delegate() { delegate_ = NULL; } 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate() { return delegate_; } 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_gesture_dragging() const { return is_gesture_dragging_; } 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::WidgetDelegate. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool CanActivate() const OVERRIDE; 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual views::NonClientFrameView* CreateNonClientFrameView( 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::Widget* widget) OVERRIDE; 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool WidgetHasHitTestMask() const OVERRIDE; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::BubbleDelegateView. 157cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Rect GetAnchorRect() const OVERRIDE; 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::View. 160cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetPreferredSize() const OVERRIDE; 161cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual gfx::Size GetMaximumSize() const OVERRIDE; 162cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual int GetHeightForWidth(int width) const OVERRIDE; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Overridden from MouseWatcherListener 1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void MouseMovedOutOfHost() OVERRIDE; 1693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TrayBubbleView(gfx::NativeView parent_window, 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::View* anchor, 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate, 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InitParams& init_params); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::BubbleDelegateView. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Init() OVERRIDE; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from views::View. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 181a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void ViewHierarchyChanged( 182a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const ViewHierarchyChangedDetails& details) OVERRIDE; 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InitParams params_; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate_; 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int preferred_width_; 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) internal::TrayBubbleBorder* bubble_border_; 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<internal::TrayBubbleContentMask> bubble_content_mask_; 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_gesture_dragging_; 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // True once the mouse cursor was actively moved by the user over the bubble. 1933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Only then the OnMouseExitedView() event will get passed on to listeners. 1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool mouse_actively_entered_; 1953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used to find any mouse movements. 1973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<MouseWatcher> mouse_watcher_; 1983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ 205