OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" | 13 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | |
16 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
17 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
18 #include "ui/views/bubble/bubble_dialog_delegate.h" | 16 #include "ui/views/bubble/bubble_dialog_delegate.h" |
19 #include "ui/views/controls/button/button.h" | 17 #include "ui/views/controls/button/button.h" |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 class WebContents; | 20 class WebContents; |
23 } // namespace content | 21 } // namespace content |
24 | 22 |
25 namespace views { | 23 namespace views { |
26 class Label; | 24 class Label; |
27 class LabelButton; | 25 class LabelButton; |
28 class View; | 26 class View; |
29 class Widget; | 27 class Widget; |
30 } // namespace views | 28 } // namespace views |
31 | 29 |
32 namespace ui { | 30 namespace ui { |
33 class Event; | 31 class Event; |
34 } // namespace ui | 32 } // namespace ui |
35 | 33 |
36 class IntentPickerLabelButton; | |
37 | |
38 // A bubble that displays a list of aplications (icons and names), after the | 34 // A bubble that displays a list of aplications (icons and names), after the |
39 // list we show a pair of buttons which allow the user to remember the selection | 35 // list we show a pair of buttons which allow the user to remember the selection |
40 // or not. This class comunicates the user's selection with a callback used by | 36 // or not. This class comunicates the user's selection with a callback used by |
41 // ArcNavigationThrottle. | 37 // ArcNavigationThrottle. |
42 // +--------------------------------+ | 38 // +--------------------------------+ |
43 // | Open with | | 39 // | Open with | |
44 // | | | 40 // | | |
45 // | Icon1 Name1 | | 41 // | Icon1 Name1 | |
46 // | Icon2 Name2 | | 42 // | Icon2 Name2 | |
47 // | ... | | 43 // | ... | |
48 // | Icon(N) Name(N) | | 44 // | Icon(N) Name(N) | |
49 // | | | 45 // | | |
50 // | [Just once] [Always] | | 46 // | [JUST ONCE] [ALWAYS] | |
51 // +--------------------------------+ | 47 // +--------------------------------+ |
52 | 48 |
53 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, | 49 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, |
54 public views::ButtonListener, | 50 public views::ButtonListener, |
55 public content::WebContentsObserver { | 51 public content::WebContentsObserver { |
56 public: | 52 public: |
57 using AppInfo = arc::ArcNavigationThrottle::AppInfo; | 53 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; |
| 54 // This callback informs the index of the app selected by the user, along with |
| 55 // the reason why the Bubble was closed. The size_t param must have a value in |
| 56 // the range [0, app_info.size()-1], except when the CloseReason is ERROR or |
| 57 // DIALOG_DEACTIVATED, for these cases we return a dummy value |
| 58 // |kAppTagNoneSelected| which won't be used at all and has no significance. |
| 59 using ThrottleCallback = |
| 60 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)>; |
58 | 61 |
59 ~IntentPickerBubbleView() override; | 62 ~IntentPickerBubbleView() override; |
60 static void ShowBubble(content::WebContents* web_contents, | 63 static void ShowBubble(content::WebContents* web_contents, |
61 const std::vector<AppInfo>& app_info, | 64 const std::vector<NameAndIcon>& app_info, |
62 const IntentPickerResponse& intent_picker_cb); | 65 const ThrottleCallback& throttle_cb); |
63 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( | 66 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( |
64 const std::vector<AppInfo>& app_info, | 67 const std::vector<NameAndIcon>& app_info, |
65 const IntentPickerResponse& intent_picker_cb, | 68 const ThrottleCallback& throttle_cb, |
66 content::WebContents* web_contents); | 69 content::WebContents* web_contents); |
67 | 70 |
68 // views::BubbleDialogDelegateView overrides: | |
69 bool Accept() override; | |
70 bool Cancel() override; | |
71 bool Close() override; | |
72 | |
73 protected: | 71 protected: |
74 // views::BubbleDialogDelegateView overrides: | 72 // views::BubbleDialogDelegateView overrides: |
75 void Init() override; | 73 void Init() override; |
76 base::string16 GetWindowTitle() const override; | |
77 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | |
78 | 74 |
79 private: | 75 private: |
80 friend class IntentPickerBubbleViewTest; | 76 friend class IntentPickerBubbleViewTest; |
81 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); | 77 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); |
82 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); | 78 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); |
83 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); | 79 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); |
84 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, VerifyStartingInkDrop); | 80 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, |
85 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, InkDropStateTransition); | 81 ThrottleCallback throttle_cb, |
86 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, PressButtonTwice); | |
87 IntentPickerBubbleView(const std::vector<AppInfo>& app_info, | |
88 IntentPickerResponse intent_picker_cb, | |
89 content::WebContents* web_contents); | 82 content::WebContents* web_contents); |
90 | 83 |
91 // views::BubbleDialogDelegateView overrides: | 84 // views::BubbleDialogDelegateView overrides: |
92 void OnWidgetDestroying(views::Widget* widget) override; | 85 void OnWidgetDestroying(views::Widget* widget) override; |
| 86 int GetDialogButtons() const override; |
93 | 87 |
94 // views::ButtonListener overrides: | 88 // views::ButtonListener overrides: |
95 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
96 | 90 |
97 // views::View overrides: | 91 // views::View overrides: |
98 gfx::Size GetPreferredSize() const override; | 92 gfx::Size GetPreferredSize() const override; |
99 | 93 |
100 // content::WebContentsObserver overrides: | 94 // content::WebContentsObserver overrides: |
101 void WebContentsDestroyed() override; | 95 void WebContentsDestroyed() override; |
102 | 96 |
103 // Retrieves the IntentPickerLabelButton* contained at position |index| from | 97 // Retrieves the LabelButton* contained at position |index| from the internal |
104 // the internal ScrollView. | 98 // ScrollView. |
105 IntentPickerLabelButton* GetIntentPickerLabelButtonAt(size_t index); | 99 views::LabelButton* GetLabelButtonAt(size_t index); |
106 void RunCallback(std::string package, | 100 void SetLabelButtonBackgroundColor(size_t index, SkColor color); |
107 arc::ArcNavigationThrottle::CloseReason close_reason); | |
108 | 101 |
109 gfx::ImageSkia GetAppImageForTesting(size_t index); | 102 // Flag set to true iff the callback was Run at some previous step, used to |
110 views::InkDropState GetInkDropStateForTesting(size_t); | 103 // ensure we only use the callback once. |
111 void PressButtonForTesting(size_t index, const ui::Event& event); | 104 bool was_callback_run_; |
112 | 105 |
113 // Callback used to respond to ArcNavigationThrottle. | 106 // Callback used to respond to ArcNavigationThrottle. |
114 IntentPickerResponse intent_picker_cb_; | 107 ThrottleCallback throttle_cb_; |
115 | 108 |
116 // Pre-select the first app on the list. | 109 // Keeps a invalid value unless the user explicitly makes a decision. |
117 size_t selected_app_tag_ = 0; | 110 size_t selected_app_tag_; |
118 | 111 |
| 112 views::LabelButton* always_button_; |
| 113 views::LabelButton* just_once_button_; |
119 views::ScrollView* scroll_view_; | 114 views::ScrollView* scroll_view_; |
120 | 115 |
121 std::vector<AppInfo> app_info_; | 116 std::vector<NameAndIcon> app_info_; |
122 | 117 |
123 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); | 118 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); |
124 }; | 119 }; |
125 | 120 |
126 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 121 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
OLD | NEW |