OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_VIEWS_CHOOSER_CONTENT_VIEW_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_CHOOSER_CONTENT_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/strings/string16.h" | |
12 #include "chrome/browser/chooser_controller/chooser_controller.h" | |
13 #include "ui/base/models/table_model.h" | |
14 #include "ui/gfx/range/range.h" | |
15 #include "ui/views/controls/styled_label_listener.h" | |
16 #include "ui/views/view.h" | |
17 | |
18 namespace views { | |
19 class StyledLabel; | |
20 class TableView; | |
21 class TableViewObserver; | |
22 class Throbber; | |
23 } | |
24 | |
25 // A bubble or dialog view for choosing among several options in a table. | |
26 // Used for WebUSB/WebBluetooth device selection for Chrome and extensions. | |
27 // | |
28 // TODO(juncai): change ChooserContentView class name to be more specific. | |
29 // https://crbug.com/651568 | |
30 class ChooserContentView : public views::View, | |
31 public ui::TableModel, | |
32 public ChooserController::View, | |
33 public views::StyledLabelListener { | |
34 public: | |
35 ChooserContentView(views::TableViewObserver* table_view_observer, | |
36 std::unique_ptr<ChooserController> chooser_controller); | |
37 ~ChooserContentView() override; | |
38 | |
39 // views::View: | |
40 gfx::Size GetPreferredSize() const override; | |
41 void Layout() override; | |
42 | |
43 // ui::TableModel: | |
44 int RowCount() override; | |
45 base::string16 GetText(int row, int column_id) override; | |
46 void SetObserver(ui::TableModelObserver* observer) override; | |
47 gfx::ImageSkia GetIcon(int row) override; | |
48 | |
49 // ChooserController::View: | |
50 void OnOptionsInitialized() override; | |
51 void OnOptionAdded(size_t index) override; | |
52 void OnOptionRemoved(size_t index) override; | |
53 void OnOptionUpdated(size_t index) override; | |
54 void OnAdapterEnabledChanged(bool enabled) override; | |
55 void OnRefreshStateChanged(bool refreshing) override; | |
56 | |
57 // views::StyledLabelListener: | |
58 void StyledLabelLinkClicked(views::StyledLabel* label, | |
59 const gfx::Range& range, | |
60 int event_flags) override; | |
61 | |
62 base::string16 GetWindowTitle() const; | |
63 base::string16 GetDialogButtonLabel(ui::DialogButton button) const; | |
64 bool IsDialogButtonEnabled(ui::DialogButton button) const; | |
65 views::StyledLabel* footnote_link(); | |
66 void Accept(); | |
67 void Cancel(); | |
68 void Close(); | |
69 void UpdateTableView(); | |
70 void SetGetHelpAndReScanLink(); | |
71 | |
72 private: | |
73 friend class ChooserContentViewTest; | |
74 friend class ChooserDialogViewTest; | |
75 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, InitialState); | |
76 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, AdapterOnAndOffAndOn); | |
77 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, | |
78 DiscoveringAndNoOptionAddedAndIdle); | |
79 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, | |
80 DiscoveringAndOneOptionAddedAndSelectedAndIdle); | |
81 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, ClickRescanLink); | |
82 FRIEND_TEST_ALL_PREFIXES(ChooserContentViewTest, ClickGetHelpLink); | |
83 | |
84 std::unique_ptr<ChooserController> chooser_controller_; | |
85 views::TableView* table_view_ = nullptr; // Weak. | |
86 views::View* table_parent_ = nullptr; // Weak. | |
87 views::StyledLabel* turn_adapter_off_help_ = nullptr; // Weak. | |
88 views::Throbber* throbber_ = nullptr; // Weak. | |
89 std::unique_ptr<views::StyledLabel> footnote_link_; | |
90 base::string16 help_text_; | |
91 base::string16 help_and_scanning_text_; | |
92 base::string16 help_and_re_scan_text_; | |
93 gfx::Range help_text_range_; | |
94 gfx::Range re_scan_text_range_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(ChooserContentView); | |
97 }; | |
98 | |
99 #endif // CHROME_BROWSER_UI_VIEWS_CHOOSER_CONTENT_VIEW_H_ | |
OLD | NEW |