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

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

Issue 2436543003: reland: Reusing Ok/Cancel buttons for intent picker (Closed)
Patch Set: Modifying the way I create a dummy event for the testing. Created 4 years, 2 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 <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"
15 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
15 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
16 #include "ui/views/bubble/bubble_dialog_delegate.h" 18 #include "ui/views/bubble/bubble_dialog_delegate.h"
17 #include "ui/views/controls/button/button.h" 19 #include "ui/views/controls/button/button.h"
18 20
19 namespace content { 21 namespace content {
20 class WebContents; 22 class WebContents;
21 } // namespace content 23 } // namespace content
22 24
23 namespace views { 25 namespace views {
24 class Label; 26 class Label;
25 class LabelButton; 27 class LabelButton;
26 class View; 28 class View;
27 class Widget; 29 class Widget;
28 } // namespace views 30 } // namespace views
29 31
30 namespace ui { 32 namespace ui {
31 class Event; 33 class Event;
32 } // namespace ui 34 } // namespace ui
33 35
36 class IntentPickerLabelButton;
37
34 // A bubble that displays a list of aplications (icons and names), after the 38 // 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 39 // 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 40 // or not. This class comunicates the user's selection with a callback used by
37 // ArcNavigationThrottle. 41 // ArcNavigationThrottle.
38 // +--------------------------------+ 42 // +--------------------------------+
39 // | Open with | 43 // | Open with |
40 // | | 44 // | |
41 // | Icon1 Name1 | 45 // | Icon1 Name1 |
42 // | Icon2 Name2 | 46 // | Icon2 Name2 |
43 // | ... | 47 // | ... |
44 // | Icon(N) Name(N) | 48 // | Icon(N) Name(N) |
45 // | | 49 // | |
46 // | [JUST ONCE] [ALWAYS] | 50 // | [Just once] [Always] |
47 // +--------------------------------+ 51 // +--------------------------------+
48 52
49 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, 53 class IntentPickerBubbleView : public views::BubbleDialogDelegateView,
50 public views::ButtonListener, 54 public views::ButtonListener,
51 public content::WebContentsObserver { 55 public content::WebContentsObserver {
52 public: 56 public:
53 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; 57 using AppInfo = arc::ArcNavigationThrottle::AppInfo;
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)>;
61 58
62 ~IntentPickerBubbleView() override; 59 ~IntentPickerBubbleView() override;
63 static void ShowBubble(content::WebContents* web_contents, 60 static void ShowBubble(content::WebContents* web_contents,
64 const std::vector<NameAndIcon>& app_info, 61 const std::vector<AppInfo>& app_info,
65 const ThrottleCallback& throttle_cb); 62 const IntentPickerResponse& intent_picker_cb);
66 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( 63 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView(
67 const std::vector<NameAndIcon>& app_info, 64 const std::vector<AppInfo>& app_info,
68 const ThrottleCallback& throttle_cb, 65 const IntentPickerResponse& intent_picker_cb,
69 content::WebContents* web_contents); 66 content::WebContents* web_contents);
70 67
68 // views::BubbleDialogDelegateView overrides:
69 bool Accept() override;
70 bool Cancel() override;
71 bool Close() override;
72
71 protected: 73 protected:
72 // views::BubbleDialogDelegateView overrides: 74 // views::BubbleDialogDelegateView overrides:
73 void Init() override; 75 void Init() override;
76 base::string16 GetWindowTitle() const override;
77 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
74 78
75 private: 79 private:
76 friend class IntentPickerBubbleViewTest; 80 friend class IntentPickerBubbleViewTest;
77 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); 81 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons);
78 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); 82 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons);
79 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); 83 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize);
80 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, 84 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, VerifyStartingInkDrop);
81 ThrottleCallback throttle_cb, 85 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, InkDropStateTransition);
86 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, PressButtonTwice);
87 IntentPickerBubbleView(const std::vector<AppInfo>& app_info,
88 IntentPickerResponse intent_picker_cb,
82 content::WebContents* web_contents); 89 content::WebContents* web_contents);
83 90
84 // views::BubbleDialogDelegateView overrides: 91 // views::BubbleDialogDelegateView overrides:
85 void OnWidgetDestroying(views::Widget* widget) override; 92 void OnWidgetDestroying(views::Widget* widget) override;
86 int GetDialogButtons() const override;
87 93
88 // views::ButtonListener overrides: 94 // views::ButtonListener overrides:
89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 95 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
90 96
91 // views::View overrides: 97 // views::View overrides:
92 gfx::Size GetPreferredSize() const override; 98 gfx::Size GetPreferredSize() const override;
93 99
94 // content::WebContentsObserver overrides: 100 // content::WebContentsObserver overrides:
95 void WebContentsDestroyed() override; 101 void WebContentsDestroyed() override;
96 102
97 // Retrieves the LabelButton* contained at position |index| from the internal 103 // Retrieves the IntentPickerLabelButton* contained at position |index| from
98 // ScrollView. 104 // the internal ScrollView.
99 views::LabelButton* GetLabelButtonAt(size_t index); 105 IntentPickerLabelButton* GetIntentPickerLabelButtonAt(size_t index);
100 void SetLabelButtonBackgroundColor(size_t index, SkColor color); 106 void RunCallback(std::string package,
107 arc::ArcNavigationThrottle::CloseReason close_reason);
101 108
102 // Flag set to true iff the callback was Run at some previous step, used to 109 gfx::ImageSkia GetAppImageForTesting(size_t index);
103 // ensure we only use the callback once. 110 views::InkDropState GetInkDropStateForTesting(size_t);
104 bool was_callback_run_; 111 void PressButtonForTesting(size_t index, const ui::Event& event);
105 112
106 // Callback used to respond to ArcNavigationThrottle. 113 // Callback used to respond to ArcNavigationThrottle.
107 ThrottleCallback throttle_cb_; 114 IntentPickerResponse intent_picker_cb_;
108 115
109 // Keeps a invalid value unless the user explicitly makes a decision. 116 // Pre-select the first app on the list.
110 size_t selected_app_tag_; 117 size_t selected_app_tag_ = 0;
111 118
112 views::LabelButton* always_button_;
113 views::LabelButton* just_once_button_;
114 views::ScrollView* scroll_view_; 119 views::ScrollView* scroll_view_;
115 120
116 std::vector<NameAndIcon> app_info_; 121 std::vector<AppInfo> app_info_;
117 122
118 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); 123 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView);
119 }; 124 };
120 125
121 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ 126 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_dialogs.h ('k') | chrome/browser/ui/views/intent_picker_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698