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

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 callback usage on WebContentsDestroyed 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 int GetDefaultDialogButton() const override;
73
71 protected: 74 protected:
72 // views::BubbleDialogDelegateView overrides: 75 // views::BubbleDialogDelegateView overrides:
73 void Init() override; 76 void Init() override;
77 base::string16 GetWindowTitle() const override;
78 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
74 79
75 private: 80 private:
76 friend class IntentPickerBubbleViewTest; 81 friend class IntentPickerBubbleViewTest;
77 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); 82 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons);
78 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); 83 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons);
79 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); 84 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize);
80 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, 85 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, VerifyStartingInkDrop);
81 ThrottleCallback throttle_cb, 86 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, InkDropStateTransition);
87 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, PressButtonTwice);
88 IntentPickerBubbleView(const std::vector<AppInfo>& app_info,
89 IntentPickerResponse intent_picker_cb,
82 content::WebContents* web_contents); 90 content::WebContents* web_contents);
83 91
84 // views::BubbleDialogDelegateView overrides: 92 // views::BubbleDialogDelegateView overrides:
85 void OnWidgetDestroying(views::Widget* widget) override; 93 void OnWidgetDestroying(views::Widget* widget) override;
86 int GetDialogButtons() const override;
87 94
88 // views::ButtonListener overrides: 95 // views::ButtonListener overrides:
89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 96 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
90 97
91 // views::View overrides: 98 // views::View overrides:
92 gfx::Size GetPreferredSize() const override; 99 gfx::Size GetPreferredSize() const override;
93 100
94 // content::WebContentsObserver overrides: 101 // content::WebContentsObserver overrides:
95 void WebContentsDestroyed() override; 102 void WebContentsDestroyed() override;
96 103
97 // Retrieves the LabelButton* contained at position |index| from the internal 104 // Retrieves the IntentPickerLabelButton* contained at position |index| from
98 // ScrollView. 105 // the internal ScrollView.
99 views::LabelButton* GetLabelButtonAt(size_t index); 106 IntentPickerLabelButton* GetIntentPickerLabelButtonAt(size_t index);
100 void SetLabelButtonBackgroundColor(size_t index, SkColor color); 107 void RunCallback(std::string package,
108 arc::ArcNavigationThrottle::CloseReason close_reason);
101 109
102 // Flag set to true iff the callback was Run at some previous step, used to 110 gfx::ImageSkia GetAppImageForTesting(size_t index);
103 // ensure we only use the callback once. 111 views::InkDropState GetInkDropStateForTesting(size_t);
104 bool was_callback_run_; 112 void PressButtonForTesting(size_t index, const ui::Event& event);
105 113
106 // Callback used to respond to ArcNavigationThrottle. 114 // Callback used to respond to ArcNavigationThrottle.
107 ThrottleCallback throttle_cb_; 115 IntentPickerResponse intent_picker_cb_;
108 116
109 // Keeps a invalid value unless the user explicitly makes a decision. 117 // Pre-select the first app on the list.
110 size_t selected_app_tag_; 118 size_t selected_app_tag_ = 0;
111 119
112 views::LabelButton* always_button_;
113 views::LabelButton* just_once_button_;
114 views::ScrollView* scroll_view_; 120 views::ScrollView* scroll_view_;
115 121
116 std::vector<NameAndIcon> app_info_; 122 std::vector<AppInfo> app_info_;
117 123
118 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); 124 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView);
119 }; 125 };
120 126
121 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ 127 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698