OLD | NEW |
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/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/host_desktop.h" |
10 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
12 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
13 #include "ui/accessibility/ax_view_state.h" | 14 #include "ui/accessibility/ax_view_state.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/events/keycodes/keyboard_codes.h" | 17 #include "ui/events/keycodes/keyboard_codes.h" |
17 #include "ui/gfx/geometry/safe_integer_conversions.h" | 18 #include "ui/gfx/geometry/safe_integer_conversions.h" |
18 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
19 #include "ui/gfx/image/image_skia_source.h" | 20 #include "ui/gfx/image/image_skia_source.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const SkColor background_color = GetNativeTheme()->GetSystemColor( | 96 const SkColor background_color = GetNativeTheme()->GetSystemColor( |
96 ui::NativeTheme::kColorId_DialogBackground); | 97 ui::NativeTheme::kColorId_DialogBackground); |
97 set_arrow(views::BubbleBorder::TOP_CENTER); | 98 set_arrow(views::BubbleBorder::TOP_CENTER); |
98 set_color(background_color); | 99 set_color(background_color); |
99 set_background(views::Background::CreateSolidBackground(background_color)); | 100 set_background(views::Background::CreateSolidBackground(background_color)); |
100 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); | 101 set_margins(gfx::Insets(views::kPanelVertMargin, 0, 0, 0)); |
101 } | 102 } |
102 | 103 |
103 void BookmarkAppBubbleView::Init() { | 104 void BookmarkAppBubbleView::Init() { |
104 views::Label* title_label = new views::Label( | 105 views::Label* title_label = new views::Label( |
105 l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_TITLE)); | 106 l10n_util::GetStringUTF16(TitleStringId())); |
106 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 107 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
107 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); | 108 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); |
108 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 109 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
109 | 110 |
110 add_button_ = | 111 add_button_ = |
111 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_ADD)); | 112 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_ADD)); |
112 add_button_->SetStyle(views::Button::STYLE_BUTTON); | 113 add_button_->SetStyle(views::Button::STYLE_BUTTON); |
113 add_button_->SetIsDefault(true); | 114 add_button_->SetIsDefault(true); |
114 | 115 |
115 cancel_button_ = | 116 cancel_button_ = |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 const ui::Accelerator& accelerator) { | 212 const ui::Accelerator& accelerator) { |
212 if (accelerator.key_code() == ui::VKEY_RETURN) { | 213 if (accelerator.key_code() == ui::VKEY_RETURN) { |
213 HandleButtonPressed(add_button_); | 214 HandleButtonPressed(add_button_); |
214 } | 215 } |
215 | 216 |
216 return BubbleDelegateView::AcceleratorPressed(accelerator); | 217 return BubbleDelegateView::AcceleratorPressed(accelerator); |
217 } | 218 } |
218 | 219 |
219 void BookmarkAppBubbleView::GetAccessibleState(ui::AXViewState* state) { | 220 void BookmarkAppBubbleView::GetAccessibleState(ui::AXViewState* state) { |
220 views::BubbleDelegateView::GetAccessibleState(state); | 221 views::BubbleDelegateView::GetAccessibleState(state); |
221 state->name = l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_TITLE); | 222 state->name = l10n_util::GetStringUTF16(TitleStringId()); |
222 } | 223 } |
223 | 224 |
224 gfx::Size BookmarkAppBubbleView::GetMinimumSize() const { | 225 gfx::Size BookmarkAppBubbleView::GetMinimumSize() const { |
225 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | 226 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); |
226 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | 227 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); |
227 return size; | 228 return size; |
228 } | 229 } |
229 | 230 |
230 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, | 231 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, |
231 const ui::Event& event) { | 232 const ui::Event& event) { |
(...skipping 14 matching lines...) Expand all Loading... |
246 web_app_info_.open_as_window = open_as_window_checkbox_->checked(); | 247 web_app_info_.open_as_window = open_as_window_checkbox_->checked(); |
247 } | 248 } |
248 | 249 |
249 GetWidget()->Close(); | 250 GetWidget()->Close(); |
250 } | 251 } |
251 | 252 |
252 void BookmarkAppBubbleView::UpdateAddButtonState() { | 253 void BookmarkAppBubbleView::UpdateAddButtonState() { |
253 add_button_->SetEnabled(!GetTrimmedTitle().empty()); | 254 add_button_->SetEnabled(!GetTrimmedTitle().empty()); |
254 } | 255 } |
255 | 256 |
| 257 int BookmarkAppBubbleView::TitleStringId() { |
| 258 #if defined(OS_WIN) |
| 259 int string_id = IDS_ADD_TO_TASKBAR_BUBBLE_TITLE; |
| 260 #else |
| 261 int string_id = IDS_ADD_TO_DESKTOP_BUBBLE_TITLE; |
| 262 #endif |
| 263 #if defined(USE_ASH) |
| 264 if (chrome::GetHostDesktopTypeForNativeWindow( |
| 265 anchor_widget()->GetNativeWindow()) == |
| 266 chrome::HOST_DESKTOP_TYPE_ASH) { |
| 267 string_id = IDS_ADD_TO_SHELF_BUBBLE_TITLE; |
| 268 } |
| 269 #endif |
| 270 return string_id; |
| 271 } |
| 272 |
256 base::string16 BookmarkAppBubbleView::GetTrimmedTitle() { | 273 base::string16 BookmarkAppBubbleView::GetTrimmedTitle() { |
257 base::string16 title(title_tf_->text()); | 274 base::string16 title(title_tf_->text()); |
258 base::TrimWhitespace(title, base::TRIM_ALL, &title); | 275 base::TrimWhitespace(title, base::TRIM_ALL, &title); |
259 return title; | 276 return title; |
260 } | 277 } |
OLD | NEW |