Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/browser/ui/views/intent_picker_bubble_view.h

Issue 2229943003: Reusing Ok/Cancel buttons for intent picker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing extra line Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 class Label; 24 class Label;
25 class LabelButton; 25 class LabelButton;
26 class View; 26 class View;
27 class Widget; 27 class Widget;
28 } // namespace views 28 } // namespace views
29 29
30 namespace ui { 30 namespace ui {
31 class Event; 31 class Event;
32 } // namespace ui 32 } // namespace ui
33 33
34 class IntentPickerLabelButton;
35
34 // A bubble that displays a list of aplications (icons and names), after the 36 // 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 37 // 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 38 // or not. This class comunicates the user's selection with a callback used by
37 // ArcNavigationThrottle. 39 // ArcNavigationThrottle.
38 // +--------------------------------+ 40 // +--------------------------------+
39 // | Open with | 41 // | Open with |
40 // | | 42 // | |
41 // | Icon1 Name1 | 43 // | Icon1 Name1 |
42 // | Icon2 Name2 | 44 // | Icon2 Name2 |
43 // | ... | 45 // | ... |
44 // | Icon(N) Name(N) | 46 // | Icon(N) Name(N) |
45 // | | 47 // | |
46 // | [JUST ONCE] [ALWAYS] | 48 // | [JUST ONCE] [ALWAYS] |
47 // +--------------------------------+ 49 // +--------------------------------+
48 50
49 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, 51 class IntentPickerBubbleView : public views::BubbleDialogDelegateView,
50 public views::ButtonListener, 52 public views::ButtonListener,
51 public content::WebContentsObserver { 53 public content::WebContentsObserver {
52 public: 54 public:
53 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; 55 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon;
54 // This callback informs the index of the app selected by the user, along with 56 // 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 57 // 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 58 // 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 59 // DIALOG_DEACTIVATED, for these cases we return a dummy value
58 // |kAppTagNoneSelected| which won't be used at all and has no significance. 60 // |kAppTagNoneSelected| which won't be used at all and has no significance.
59 using ThrottleCallback = 61 using IntentPickerResponse =
60 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)>; 62 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)>;
61 63
62 ~IntentPickerBubbleView() override; 64 ~IntentPickerBubbleView() override;
63 static void ShowBubble(content::WebContents* web_contents, 65 static void ShowBubble(content::WebContents* web_contents,
64 const std::vector<NameAndIcon>& app_info, 66 const std::vector<NameAndIcon>& app_info,
65 const ThrottleCallback& throttle_cb); 67 const IntentPickerResponse& intent_picker_cb);
66 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( 68 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView(
67 const std::vector<NameAndIcon>& app_info, 69 const std::vector<NameAndIcon>& app_info,
68 const ThrottleCallback& throttle_cb, 70 const IntentPickerResponse& intent_picker_cb,
69 content::WebContents* web_contents); 71 content::WebContents* web_contents);
70 72
73 // views::DialogDelegate overrides:
74 bool Accept() override;
75 bool Cancel() override;
76 bool Close() override;
77 int GetDefaultDialogButton() const override;
78
71 protected: 79 protected:
72 // views::BubbleDialogDelegateView overrides: 80 // views::BubbleDialogDelegateView overrides:
73 void Init() override; 81 void Init() override;
74 82
83 // views::DialogDelegate overrides:
84 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
85
86 // views::WidgetDelegate overrides:
87 base::string16 GetWindowTitle() const override;
88 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
89
75 private: 90 private:
76 friend class IntentPickerBubbleViewTest; 91 friend class IntentPickerBubbleViewTest;
77 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); 92 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons);
78 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); 93 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons);
79 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); 94 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize);
95 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, VerifyStartingInkDrop);
96 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, InkDropStateTransition);
97 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, PressButtonTwice);
80 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, 98 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info,
81 ThrottleCallback throttle_cb, 99 IntentPickerResponse intent_picker_cb,
82 content::WebContents* web_contents); 100 content::WebContents* web_contents);
83 101
84 // views::BubbleDialogDelegateView overrides: 102 // views::BubbleDialogDelegateView overrides:
85 void OnWidgetDestroying(views::Widget* widget) override; 103 void OnWidgetDestroying(views::Widget* widget) override;
86 int GetDialogButtons() const override;
87 104
88 // views::ButtonListener overrides: 105 // views::ButtonListener overrides:
89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 106 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
90 107
91 // views::View overrides: 108 // views::View overrides:
92 gfx::Size GetPreferredSize() const override; 109 gfx::Size GetPreferredSize() const override;
93 110
94 // content::WebContentsObserver overrides: 111 // content::WebContentsObserver overrides:
95 void WebContentsDestroyed() override; 112 void WebContentsDestroyed() override;
96 113
97 // Retrieves the LabelButton* contained at position |index| from the internal 114 // Retrieves the IntentPickerLabelButton* contained at position |index| from
98 // ScrollView. 115 // the internal ScrollView.
99 views::LabelButton* GetLabelButtonAt(size_t index); 116 IntentPickerLabelButton* GetIntentPickerLabelButtonAt(size_t index);
100 void SetLabelButtonBackgroundColor(size_t index, SkColor color);
101 117
102 // Flag set to true iff the callback was Run at some previous step, used to 118 gfx::ImageSkia GetAppImageForTesting(size_t index);
103 // ensure we only use the callback once. 119 views::InkDropState GetInkDropStateForTesting(size_t);
104 bool was_callback_run_; 120 void PressButtonForTesting(size_t index, const ui::Event& event);
105 121
106 // Callback used to respond to ArcNavigationThrottle. 122 // Callback used to respond to ArcNavigationThrottle.
107 ThrottleCallback throttle_cb_; 123 IntentPickerResponse intent_picker_cb_;
108 124
109 // Keeps a invalid value unless the user explicitly makes a decision. 125 // Keeps a invalid value unless the user explicitly makes a decision.
110 size_t selected_app_tag_; 126 size_t selected_app_tag_;
111 127
112 views::LabelButton* always_button_;
113 views::LabelButton* just_once_button_;
114 views::ScrollView* scroll_view_; 128 views::ScrollView* scroll_view_;
115 129
116 std::vector<NameAndIcon> app_info_; 130 std::vector<NameAndIcon> app_info_;
117 131
118 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); 132 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView);
119 }; 133 };
120 134
121 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ 135 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698