1 // Copyright 2017 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 ASH_LOGIN_UI_LOGIN_BASE_BUBBLE_VIEW_H_ 6 #define ASH_LOGIN_UI_LOGIN_BASE_BUBBLE_VIEW_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/login/ui/login_button.h" 10 #include "ui/compositor/layer_animation_observer.h" 11 #include "ui/views/bubble/bubble_dialog_delegate_view.h" 12 #include "ui/views/view.h" 13 #include "ui/views/widget/widget_observer.h" 14 15 namespace ash { 16 17 class LoginBubbleHandler; 18 19 // Base bubble view for login screen bubbles. 20 class ASH_EXPORT LoginBaseBubbleView : public views::View, 21 public ui::LayerAnimationObserver { 22 public: 23 enum class PositioningStrategy { 24 // Try to show the bubble after the anchor (on the right side in LTR), if 25 // there is no space show before. 26 kTryAfterThenBefore, 27 // Try to show the bubble before the anchor (on the left side in LTR), if 28 // there is no space show after. 29 kTryBeforeThenAfter, 30 // Show the bubble above the anchor. 31 kShowAbove, 32 // Show the bubble on the bottom left of the anchor. 33 kShowBelow, 34 }; 35 36 // Without specifying a parent_window, the bubble will default to being in the 37 // same container as anchor_view. 38 explicit LoginBaseBubbleView(views::View* anchor_view); 39 explicit LoginBaseBubbleView(views::View* anchor_view, 40 gfx::NativeView parent_window); 41 ~LoginBaseBubbleView() override; 42 LoginBaseBubbleView(const LoginBaseBubbleView&) = delete; 43 LoginBaseBubbleView& operator=(const LoginBaseBubbleView&) = delete; 44 45 void Show(); 46 void Hide(); 47 48 // Returns the button responsible for opening this bubble. 49 virtual LoginButton* GetBubbleOpener() const; 50 51 // Returns whether or not this bubble should show persistently. is_persistent()52 bool is_persistent() const { return is_persistent_; } 53 // Change the persistence of the bubble. set_persistent(bool is_persistent)54 void set_persistent(bool is_persistent) { is_persistent_ = is_persistent; } 55 56 void SetAnchorView(views::View* anchor_view); GetAnchorView()57 views::View* GetAnchorView() const { return anchor_view_; } 58 59 // ui::LayerAnimationObserver: 60 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override; 61 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override; OnLayerAnimationScheduled(ui::LayerAnimationSequence * sequence)62 void OnLayerAnimationScheduled( 63 ui::LayerAnimationSequence* sequence) override {} 64 65 // views::View: 66 gfx::Size CalculatePreferredSize() const override; 67 void Layout() override; 68 void OnBlur() override; 69 set_positioning_strategy(PositioningStrategy positioning_strategy)70 void set_positioning_strategy(PositioningStrategy positioning_strategy) { 71 positioning_strategy_ = positioning_strategy; 72 } 73 void SetPadding(int horizontal_padding, int vertical_padding); 74 75 protected: 76 // Return area where bubble could be shown in. 77 gfx::Rect GetBoundsAvailableToShowBubble() const; 78 set_notify_alert_on_show(bool notify_alert_on_show)79 void set_notify_alert_on_show(bool notify_alert_on_show) { 80 notify_a11y_alert_on_show_ = notify_alert_on_show; 81 } 82 83 private: 84 // Create a layer for this view if doesn't exist. 85 void EnsureLayer(); 86 87 // Return bounds of the anchors root view. This bounds excludes virtual 88 // keyboard. 89 gfx::Rect GetRootViewBounds() const; 90 // Return bounds of working area. This bounds excludes shelf. 91 gfx::Rect GetWorkArea() const; 92 void ScheduleAnimation(bool visible); 93 94 // Determine the position of the bubble prior to showing. 95 gfx::Point CalculatePosition(); 96 97 views::View* anchor_view_; 98 99 std::unique_ptr<LoginBubbleHandler> bubble_handler_; 100 101 bool is_persistent_ = false; 102 103 // Positioning strategy of the bubble. 104 PositioningStrategy positioning_strategy_ = PositioningStrategy::kShowBelow; 105 int horizontal_padding_ = 0; 106 int vertical_padding_ = 0; 107 108 // Whether or not to read an alert when the bubble is shown. 109 bool notify_a11y_alert_on_show_ = true; 110 }; 111 112 } // namespace ash 113 114 #endif // ASH_LOGIN_UI_LOGIN_BASE_BUBBLE_VIEW_H_ 115