OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 rb.GetBitmapNamed(IDR_BROWSER_ACTION_P)->copyTo(&bg_p, | 158 rb.GetBitmapNamed(IDR_BROWSER_ACTION_P)->copyTo(&bg_p, |
159 SkBitmap::kARGB_8888_Config); | 159 SkBitmap::kARGB_8888_Config); |
160 SkCanvas bg_p_canvas(bg_p); | 160 SkCanvas bg_p_canvas(bg_p); |
161 bg_p_canvas.drawBitmap(icon, | 161 bg_p_canvas.drawBitmap(icon, |
162 SkIntToScalar((bg_p.width() - icon.width()) / 2), | 162 SkIntToScalar((bg_p.width() - icon.width()) / 2), |
163 SkIntToScalar((bg_p.height() - icon.height()) / 2), &paint); | 163 SkIntToScalar((bg_p.height() - icon.height()) / 2), &paint); |
164 SetPushedIcon(bg_p); | 164 SetPushedIcon(bg_p); |
165 } | 165 } |
166 | 166 |
167 // If the browser action name is empty, show the extension name instead. | 167 // If the browser action name is empty, show the extension name instead. |
168 std::wstring name = UTF8ToWide(browser_action()->GetTitle(tab_id)); | 168 string16 name = UTF8ToUTF16(browser_action()->GetTitle(tab_id)); |
169 if (name.empty()) | 169 if (name.empty()) |
170 name = UTF8ToWide(extension()->name()); | 170 name = UTF8ToUTF16(extension()->name()); |
171 SetTooltipText(name); | 171 SetTooltipText(UTF16ToWideHack(name)); |
172 SetAccessibleName(name); | 172 SetAccessibleName(name); |
173 GetParent()->SchedulePaint(); | 173 GetParent()->SchedulePaint(); |
174 } | 174 } |
175 | 175 |
176 void BrowserActionButton::Observe(NotificationType type, | 176 void BrowserActionButton::Observe(NotificationType type, |
177 const NotificationSource& source, | 177 const NotificationSource& source, |
178 const NotificationDetails& details) { | 178 const NotificationDetails& details) { |
179 DCHECK(type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED); | 179 DCHECK(type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED); |
180 UpdateState(); | 180 UpdateState(); |
181 // The browser action may have become visible/hidden so we need to make | 181 // The browser action may have become visible/hidden so we need to make |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 //////////////////////////////////////////////////////////////////////////////// | 281 //////////////////////////////////////////////////////////////////////////////// |
282 // BrowserActionView | 282 // BrowserActionView |
283 | 283 |
284 BrowserActionView::BrowserActionView(const Extension* extension, | 284 BrowserActionView::BrowserActionView(const Extension* extension, |
285 BrowserActionsContainer* panel) | 285 BrowserActionsContainer* panel) |
286 : panel_(panel) { | 286 : panel_(panel) { |
287 button_ = new BrowserActionButton(extension, panel); | 287 button_ = new BrowserActionButton(extension, panel); |
288 button_->SetDragController(panel_); | 288 button_->SetDragController(panel_); |
289 AddChildView(button_); | 289 AddChildView(button_); |
290 button_->UpdateState(); | 290 button_->UpdateState(); |
291 SetAccessibleName(UTF16ToWide( | 291 SetAccessibleName( |
292 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION))); | 292 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION)); |
293 } | 293 } |
294 | 294 |
295 BrowserActionView::~BrowserActionView() { | 295 BrowserActionView::~BrowserActionView() { |
296 RemoveChildView(button_); | 296 RemoveChildView(button_); |
297 button_->Destroy(); | 297 button_->Destroy(); |
298 } | 298 } |
299 | 299 |
300 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 300 gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
301 int tab_id = panel_->GetCurrentTabId(); | 301 int tab_id = panel_->GetCurrentTabId(); |
302 | 302 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
363 | 363 |
364 if (profile_->GetExtensionService()) { | 364 if (profile_->GetExtensionService()) { |
365 model_ = profile_->GetExtensionService()->toolbar_model(); | 365 model_ = profile_->GetExtensionService()->toolbar_model(); |
366 model_->AddObserver(this); | 366 model_->AddObserver(this); |
367 } | 367 } |
368 | 368 |
369 resize_animation_.reset(new ui::SlideAnimation(this)); | 369 resize_animation_.reset(new ui::SlideAnimation(this)); |
370 resize_area_ = new views::ResizeArea(this); | 370 resize_area_ = new views::ResizeArea(this); |
371 resize_area_->SetAccessibleName( | 371 resize_area_->SetAccessibleName( |
372 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR))); | 372 l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR)); |
373 AddChildView(resize_area_); | 373 AddChildView(resize_area_); |
374 | 374 |
375 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); | 375 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); |
376 chevron_->set_border(NULL); | 376 chevron_->set_border(NULL); |
377 chevron_->EnableCanvasFlippingForRTLUI(true); | 377 chevron_->EnableCanvasFlippingForRTLUI(true); |
378 chevron_->SetAccessibleName( | 378 chevron_->SetAccessibleName( |
379 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON))); | 379 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); |
380 chevron_->SetVisible(false); | 380 chevron_->SetVisible(false); |
381 AddChildView(chevron_); | 381 AddChildView(chevron_); |
382 | 382 |
383 SetAccessibleName( | 383 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS)); |
384 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS))); | |
385 } | 384 } |
386 | 385 |
387 BrowserActionsContainer::~BrowserActionsContainer() { | 386 BrowserActionsContainer::~BrowserActionsContainer() { |
388 if (model_) | 387 if (model_) |
389 model_->RemoveObserver(this); | 388 model_->RemoveObserver(this); |
390 StopShowFolderDropMenuTimer(); | 389 StopShowFolderDropMenuTimer(); |
391 HidePopup(); | 390 HidePopup(); |
392 DeleteBrowserActionViews(); | 391 DeleteBrowserActionViews(); |
393 } | 392 } |
394 | 393 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 AnimationEnded(resize_animation_.get()); | 1093 AnimationEnded(resize_animation_.get()); |
1095 } | 1094 } |
1096 } | 1095 } |
1097 | 1096 |
1098 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1097 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1099 const Extension* extension) { | 1098 const Extension* extension) { |
1100 // Only display incognito-enabled extensions while in incognito mode. | 1099 // Only display incognito-enabled extensions while in incognito mode. |
1101 return (!profile_->IsOffTheRecord() || | 1100 return (!profile_->IsOffTheRecord() || |
1102 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); | 1101 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); |
1103 } | 1102 } |
OLD | NEW |