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

Side by Side Diff: chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc

Issue 184213006: Add icon to the streamlined hosted app creation dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares_hide_search_box
Patch Set: Created 6 years, 9 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
« no previous file with comments | « chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h" 5 #include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/app_icon_loader_impl.h"
9 #include "chrome/browser/extensions/crx_installer.h" 10 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/launch_util.h" 11 #include "chrome/browser/extensions/launch_util.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "extensions/browser/pref_names.h" 13 #include "extensions/browser/pref_names.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/events/keycodes/keyboard_codes.h" 18 #include "ui/events/keycodes/keyboard_codes.h"
18 #include "ui/views/controls/button/checkbox.h" 19 #include "ui/views/controls/button/checkbox.h"
19 #include "ui/views/controls/button/label_button.h" 20 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/textfield/textfield.h" 23 #include "ui/views/controls/textfield/textfield.h"
22 #include "ui/views/layout/grid_layout.h" 24 #include "ui/views/layout/grid_layout.h"
23 #include "ui/views/layout/layout_constants.h" 25 #include "ui/views/layout/layout_constants.h"
24 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
25 27
26 using views::ColumnSet; 28 using views::ColumnSet;
27 using views::GridLayout; 29 using views::GridLayout;
28 30
29 namespace { 31 namespace {
30 32
31 // Minimum width of the the bubble. 33 // Minimum width of the the bubble.
32 const int kMinBubbleWidth = 300; 34 const int kMinBubbleWidth = 300;
33 // Minimum width of the the textfield. 35 // Minimum width of the the textfield.
34 const int kMinTextfieldWidth = 200; 36 const int kMinTextfieldWidth = 200;
37 // Size of the icon.
38 const int kIconSize = extension_misc::EXTENSION_ICON_MEDIUM;
35 39
36 } // namespace 40 } // namespace
37 41
38 BookmarkAppBubbleView* BookmarkAppBubbleView::bookmark_app_bubble_ = NULL; 42 BookmarkAppBubbleView* BookmarkAppBubbleView::bookmark_app_bubble_ = NULL;
39 43
40 BookmarkAppBubbleView::~BookmarkAppBubbleView() { 44 BookmarkAppBubbleView::~BookmarkAppBubbleView() {
41 } 45 }
42 46
43 // static 47 // static
44 void BookmarkAppBubbleView::ShowBubble(views::View* anchor_view, 48 void BookmarkAppBubbleView::ShowBubble(views::View* anchor_view,
(...skipping 17 matching lines...) Expand all
62 const WebApplicationInfo& web_app_info, 66 const WebApplicationInfo& web_app_info,
63 const std::string& extension_id) 67 const std::string& extension_id)
64 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 68 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
65 profile_(profile), 69 profile_(profile),
66 web_app_info_(web_app_info), 70 web_app_info_(web_app_info),
67 extension_id_(extension_id), 71 extension_id_(extension_id),
68 add_button_(NULL), 72 add_button_(NULL),
69 cancel_button_(NULL), 73 cancel_button_(NULL),
70 open_as_tab_checkbox_(NULL), 74 open_as_tab_checkbox_(NULL),
71 title_tf_(NULL), 75 title_tf_(NULL),
72 remove_app_(true) { 76 remove_app_(true),
77 app_icon_loader_(new extensions::AppIconLoaderImpl(profile,
78 kIconSize,
79 this)) {
73 const SkColor background_color = GetNativeTheme()->GetSystemColor( 80 const SkColor background_color = GetNativeTheme()->GetSystemColor(
74 ui::NativeTheme::kColorId_DialogBackground); 81 ui::NativeTheme::kColorId_DialogBackground);
75 set_arrow(views::BubbleBorder::TOP_CENTER); 82 set_arrow(views::BubbleBorder::TOP_CENTER);
76 set_color(background_color); 83 set_color(background_color);
77 set_background(views::Background::CreateSolidBackground(background_color)); 84 set_background(views::Background::CreateSolidBackground(background_color));
78 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); 85 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0));
79 } 86 }
80 87
81 void BookmarkAppBubbleView::Init() { 88 void BookmarkAppBubbleView::Init() {
82 views::Label* title_label = new views::Label( 89 views::Label* title_label = new views::Label(
(...skipping 21 matching lines...) Expand all
104 CONTENT_COLUMN_SET_ID 111 CONTENT_COLUMN_SET_ID
105 }; 112 };
106 113
107 // The column layout used for the title and checkbox. 114 // The column layout used for the title and checkbox.
108 ColumnSet* cs = layout->AddColumnSet(TITLE_COLUMN_SET_ID); 115 ColumnSet* cs = layout->AddColumnSet(TITLE_COLUMN_SET_ID);
109 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 116 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
110 cs->AddColumn( 117 cs->AddColumn(
111 GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 118 GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
112 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 119 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
113 120
114 // The column layout used for the text box. 121 // The column layout used for the icon and text box.
115 cs = layout->AddColumnSet(TITLE_TEXT_COLUMN_SET_ID); 122 cs = layout->AddColumnSet(TITLE_TEXT_COLUMN_SET_ID);
116 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 123 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
124 cs->AddColumn(GridLayout::LEADING,
125 GridLayout::CENTER,
126 0,
127 GridLayout::USE_PREF,
128 0,
129 0);
130 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
117 cs->AddColumn(GridLayout::FILL, 131 cs->AddColumn(GridLayout::FILL,
118 GridLayout::FILL, 132 GridLayout::CENTER,
119 1, 133 1,
120 GridLayout::USE_PREF, 134 GridLayout::USE_PREF,
121 0, 135 0,
122 kMinTextfieldWidth); 136 kMinTextfieldWidth);
123 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 137 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
124 138
125 // The column layout used for the row with buttons. 139 // The column layout used for the row with buttons.
126 cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID); 140 cs = layout->AddColumnSet(CONTENT_COLUMN_SET_ID);
127 cs->AddPaddingColumn(1, views::kButtonHEdgeMarginNew); 141 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
128
129 cs->AddColumn( 142 cs->AddColumn(
130 GridLayout::LEADING, GridLayout::TRAILING, 0, GridLayout::USE_PREF, 0, 0); 143 GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
144 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
145 cs->AddColumn(
146 GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
131 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 147 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
132 cs->AddColumn( 148 cs->AddColumn(
133 GridLayout::LEADING, GridLayout::TRAILING, 0, GridLayout::USE_PREF, 0, 0); 149 GridLayout::LEADING, GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
134 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 150 cs->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
135 151
136 layout->StartRow(0, TITLE_COLUMN_SET_ID); 152 layout->StartRow(0, TITLE_COLUMN_SET_ID);
137 layout->AddView(title_label); 153 layout->AddView(title_label);
138 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 154 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
139 155
140 layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID);
141 title_tf_ = new views::Textfield();
142 const extensions::Extension* extension = 156 const extensions::Extension* extension =
143 profile_->GetExtensionService()->GetInstalledExtension(extension_id_); 157 profile_->GetExtensionService()->GetInstalledExtension(extension_id_);
158
159 layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID);
160 icon_image_view_ = new views::ImageView();
161 icon_image_view_->SetImageSize(gfx::Size(kIconSize, kIconSize));
162 layout->AddView(icon_image_view_);
163 app_icon_loader_->FetchImage(extension_id_);
164
165 title_tf_ = new views::Textfield();
144 title_tf_->SetText(extension ? base::UTF8ToUTF16(extension->name()) 166 title_tf_->SetText(extension ? base::UTF8ToUTF16(extension->name())
145 : web_app_info_.title); 167 : web_app_info_.title);
146 layout->AddView(title_tf_); 168 layout->AddView(title_tf_);
147 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 169 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
148 170
149 layout->StartRow(0, TITLE_COLUMN_SET_ID); 171 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
150 open_as_tab_checkbox_ = new views::Checkbox( 172 open_as_tab_checkbox_ = new views::Checkbox(
151 l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)); 173 l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB));
152 open_as_tab_checkbox_->SetChecked( 174 open_as_tab_checkbox_->SetChecked(
153 profile_->GetPrefs()->GetInteger( 175 profile_->GetPrefs()->GetInteger(
154 extensions::pref_names::kBookmarkAppCreationLaunchType) == 176 extensions::pref_names::kBookmarkAppCreationLaunchType) ==
155 extensions::LAUNCH_TYPE_REGULAR); 177 extensions::LAUNCH_TYPE_REGULAR);
156 layout->AddView(open_as_tab_checkbox_); 178 layout->AddView(open_as_tab_checkbox_);
157 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
158
159 layout->StartRow(0, CONTENT_COLUMN_SET_ID);
160 layout->AddView(add_button_); 179 layout->AddView(add_button_);
161 layout->AddView(cancel_button_); 180 layout->AddView(cancel_button_);
162 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 181 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
163 182
164 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 183 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
165 } 184 }
166 185
167 views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() { 186 views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() {
168 return title_tf_; 187 return title_tf_;
169 } 188 }
(...skipping 26 matching lines...) Expand all
196 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); 215 gfx::Size size(views::BubbleDelegateView::GetPreferredSize());
197 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); 216 size.SetToMax(gfx::Size(kMinBubbleWidth, 0));
198 return size; 217 return size;
199 } 218 }
200 219
201 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, 220 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender,
202 const ui::Event& event) { 221 const ui::Event& event) {
203 HandleButtonPressed(sender); 222 HandleButtonPressed(sender);
204 } 223 }
205 224
225 void BookmarkAppBubbleView::SetAppImage(const std::string& id,
226 const gfx::ImageSkia& image) {
227 DCHECK_EQ(extension_id_, id);
228 icon_image_view_->SetImage(image);
229 }
230
206 void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) { 231 void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) {
207 // Unset |remove_app_| so we don't delete the bookmark after the window 232 // Unset |remove_app_| so we don't delete the bookmark after the window
208 // closes. 233 // closes.
209 if (sender == add_button_) 234 if (sender == add_button_)
210 remove_app_ = false; 235 remove_app_ = false;
211 236
212 StartFade(false); 237 StartFade(false);
213 } 238 }
214 239
215 void BookmarkAppBubbleView::ApplyEdits() { 240 void BookmarkAppBubbleView::ApplyEdits() {
(...skipping 14 matching lines...) Expand all
230 255
231 // Reinstall the app with an updated name. 256 // Reinstall the app with an updated name.
232 WebApplicationInfo install_info(web_app_info_); 257 WebApplicationInfo install_info(web_app_info_);
233 install_info.title = title_tf_->text(); 258 install_info.title = title_tf_->text();
234 259
235 scoped_refptr<extensions::CrxInstaller> installer( 260 scoped_refptr<extensions::CrxInstaller> installer(
236 extensions::CrxInstaller::CreateSilent(profile_->GetExtensionService())); 261 extensions::CrxInstaller::CreateSilent(profile_->GetExtensionService()));
237 installer->set_error_on_unsupported_requirements(true); 262 installer->set_error_on_unsupported_requirements(true);
238 installer->InstallWebApp(install_info); 263 installer->InstallWebApp(install_info);
239 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698