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