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/panels/panel_browser_frame_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_service.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
7 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
8 #include "chrome/browser/ui/panels/about_panel_bubble.h" | |
9 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_browser_view.h" | 11 #include "chrome/browser/ui/panels/panel_browser_view.h" |
11 #include "chrome/browser/ui/panels/panel_manager.h" | 12 #include "chrome/browser/ui/panels/panel_manager.h" |
13 #include "chrome/common/extensions/extension.h" | |
14 #include "chrome/common/url_constants.h" | |
12 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "grit/app_resources.h" | 16 #include "grit/app_resources.h" |
14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
15 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
16 #include "grit/theme_resources_standard.h" | 19 #include "grit/theme_resources_standard.h" |
17 #include "third_party/skia/include/effects/SkGradientShader.h" | 20 #include "third_party/skia/include/effects/SkGradientShader.h" |
18 #include "ui/base/accessibility/accessible_view_state.h" | 21 #include "ui/base/accessibility/accessible_view_state.h" |
19 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/canvas_skia.h" | 24 #include "ui/gfx/canvas_skia.h" |
22 #include "views/controls/button/image_button.h" | 25 #include "views/controls/button/image_button.h" |
26 #include "views/controls/button/menu_button.h" | |
23 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
28 #include "views/controls/menu/menu_2.h" | |
24 #include "views/painter.h" | 29 #include "views/painter.h" |
25 #include "views/screen.h" | 30 #include "views/screen.h" |
26 #include "views/window/window.h" | 31 #include "views/window/window.h" |
27 #include "views/window/window_shape.h" | 32 #include "views/window/window_shape.h" |
28 | 33 |
29 #if !defined(OS_WIN) | 34 #if !defined(OS_WIN) |
30 #include "views/window/hit_test.h" | 35 #include "views/window/hit_test.h" |
31 #endif | 36 #endif |
32 | 37 |
33 namespace { | 38 namespace { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 top = rb.GetBitmapNamed(top_id); | 86 top = rb.GetBitmapNamed(top_id); |
82 top_right = rb.GetBitmapNamed(top_right_id); | 87 top_right = rb.GetBitmapNamed(top_right_id); |
83 right = rb.GetBitmapNamed(right_id); | 88 right = rb.GetBitmapNamed(right_id); |
84 bottom_right = rb.GetBitmapNamed(bottom_right_id); | 89 bottom_right = rb.GetBitmapNamed(bottom_right_id); |
85 bottom = rb.GetBitmapNamed(bottom_id); | 90 bottom = rb.GetBitmapNamed(bottom_id); |
86 bottom_left = rb.GetBitmapNamed(bottom_left_id); | 91 bottom_left = rb.GetBitmapNamed(bottom_left_id); |
87 left = rb.GetBitmapNamed(left_id); | 92 left = rb.GetBitmapNamed(left_id); |
88 } | 93 } |
89 }; | 94 }; |
90 | 95 |
91 ButtonResources info_button_resources; | 96 ButtonResources settings_button_resources; |
92 ButtonResources close_button_resources; | 97 ButtonResources close_button_resources; |
93 EdgeResources frame_edges; | 98 EdgeResources frame_edges; |
94 EdgeResources client_edges; | 99 EdgeResources client_edges; |
95 gfx::Font* active_font = NULL; | 100 gfx::Font* active_font = NULL; |
96 gfx::Font* inactive_font = NULL; | 101 gfx::Font* inactive_font = NULL; |
97 | 102 |
98 void LoadImageResources() { | 103 void LoadImageResources() { |
99 // TODO(jianli): Use the right icon for the info button. | 104 settings_button_resources.SetResources( |
100 info_button_resources.SetResources( | |
101 IDR_BALLOON_WRENCH, 0, IDR_BALLOON_WRENCH_H, IDR_BALLOON_WRENCH_P); | 105 IDR_BALLOON_WRENCH, 0, IDR_BALLOON_WRENCH_H, IDR_BALLOON_WRENCH_P); |
102 | 106 |
103 close_button_resources.SetResources( | 107 close_button_resources.SetResources( |
104 IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); | 108 IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); |
105 | 109 |
106 frame_edges.SetResources( | 110 frame_edges.SetResources( |
107 IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_CENTER, | 111 IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_CENTER, |
108 IDR_WINDOW_TOP_RIGHT_CORNER, IDR_WINDOW_RIGHT_SIDE, | 112 IDR_WINDOW_TOP_RIGHT_CORNER, IDR_WINDOW_RIGHT_SIDE, |
109 IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_BOTTOM_CENTER, | 113 IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_BOTTOM_CENTER, |
110 IDR_WINDOW_BOTTOM_LEFT_CORNER, IDR_WINDOW_LEFT_SIDE); | 114 IDR_WINDOW_BOTTOM_LEFT_CORNER, IDR_WINDOW_LEFT_SIDE); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 } | 188 } |
185 | 189 |
186 // PanelBrowserFrameView ------------------------------------------------------- | 190 // PanelBrowserFrameView ------------------------------------------------------- |
187 | 191 |
188 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, | 192 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, |
189 PanelBrowserView* browser_view) | 193 PanelBrowserView* browser_view) |
190 : BrowserNonClientFrameView(), | 194 : BrowserNonClientFrameView(), |
191 frame_(frame), | 195 frame_(frame), |
192 browser_view_(browser_view), | 196 browser_view_(browser_view), |
193 paint_state_(NOT_PAINTED), | 197 paint_state_(NOT_PAINTED), |
194 info_button_(NULL), | 198 settings_button_(NULL), |
195 close_button_(NULL), | 199 close_button_(NULL), |
196 title_icon_(NULL), | 200 title_icon_(NULL), |
197 title_label_(NULL) { | 201 title_label_(NULL) { |
198 EnsureResourcesInitialized(); | 202 EnsureResourcesInitialized(); |
199 frame_->set_frame_type(views::Window::FRAME_TYPE_FORCE_CUSTOM); | 203 frame_->set_frame_type(views::Window::FRAME_TYPE_FORCE_CUSTOM); |
200 | 204 |
201 info_button_ = new views::ImageButton(this); | 205 settings_button_ = new views::MenuButton(NULL, std::wstring(), this, false); |
202 info_button_->SetImage(views::CustomButton::BS_NORMAL, | 206 settings_button_->SetIcon(*(settings_button_resources.normal_image)); |
203 info_button_resources.normal_image); | 207 settings_button_->SetHoverIcon(*(settings_button_resources.hover_image)); |
204 info_button_->SetImage(views::CustomButton::BS_HOT, | 208 settings_button_->SetPushedIcon(*(settings_button_resources.pushed_image)); |
205 info_button_resources.hover_image); | 209 settings_button_->set_alignment(views::TextButton::ALIGN_CENTER); |
206 info_button_->SetImage(views::CustomButton::BS_PUSHED, | 210 settings_button_->set_border(NULL); |
207 info_button_resources.pushed_image); | 211 settings_button_->SetTooltipText( |
208 info_button_->SetTooltipText( | 212 UTF16ToWide(l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_SETTINGS))); |
209 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL))); | 213 settings_button_->SetAccessibleName( |
210 info_button_->SetAccessibleName( | 214 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_SETTINGS)); |
211 l10n_util::GetStringUTF16(IDS_ACCNAME_ABOUT_PANEL)); | 215 settings_button_->SetVisible(false); |
212 info_button_->SetVisible(false); | 216 AddChildView(settings_button_); |
213 AddChildView(info_button_); | |
214 | 217 |
215 close_button_ = new views::ImageButton(this); | 218 close_button_ = new views::ImageButton(this); |
216 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 219 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
217 close_button_resources.normal_image); | 220 close_button_resources.normal_image); |
218 close_button_->SetImage(views::CustomButton::BS_HOT, | 221 close_button_->SetImage(views::CustomButton::BS_HOT, |
219 close_button_resources.hover_image); | 222 close_button_resources.hover_image); |
220 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 223 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
221 close_button_resources.pushed_image); | 224 close_button_resources.pushed_image); |
222 close_button_->SetTooltipText( | 225 close_button_->SetTooltipText( |
223 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB))); | 226 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_CLOSE_TAB))); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 PAINT_AS_ACTIVE : PAINT_AS_INACTIVE); | 320 PAINT_AS_ACTIVE : PAINT_AS_INACTIVE); |
318 PaintFrameBorder(canvas); | 321 PaintFrameBorder(canvas); |
319 PaintClientEdge(canvas); | 322 PaintClientEdge(canvas); |
320 } | 323 } |
321 | 324 |
322 void PanelBrowserFrameView::OnThemeChanged() { | 325 void PanelBrowserFrameView::OnThemeChanged() { |
323 LoadImageResources(); | 326 LoadImageResources(); |
324 } | 327 } |
325 | 328 |
326 void PanelBrowserFrameView::Layout() { | 329 void PanelBrowserFrameView::Layout() { |
327 // Now that we know we have a parent, we can safely set our theme colors. | |
328 SkColor title_color = | |
329 GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT); | |
330 title_label_->SetColor(title_color); | |
331 close_button_->SetBackground(title_color, | |
332 close_button_resources.normal_image, | |
333 close_button_resources.mask_image); | |
334 | |
335 // Layout the close button. | 330 // Layout the close button. |
336 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 331 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
337 close_button_->SetBounds( | 332 close_button_->SetBounds( |
338 width() - kFrameBorderThickness - kButtonSpacing - | 333 width() - kFrameBorderThickness - kButtonSpacing - |
339 close_button_size.width(), | 334 close_button_size.width(), |
340 (NonClientTopBorderHeight() - close_button_size.height()) / 2, | 335 (NonClientTopBorderHeight() - close_button_size.height()) / 2, |
341 close_button_size.width(), | 336 close_button_size.width(), |
342 close_button_size.height()); | 337 close_button_size.height()); |
343 | 338 |
344 // Layout the info button. | 339 // Layout the settings button. |
345 gfx::Size info_button_size = info_button_->GetPreferredSize(); | 340 gfx::Size settings_button_size = settings_button_->GetPreferredSize(); |
346 info_button_->SetBounds( | 341 settings_button_->SetBounds( |
347 close_button_->x() - kButtonSpacing - info_button_size.width(), | 342 close_button_->x() - kButtonSpacing - settings_button_size.width(), |
348 (NonClientTopBorderHeight() - info_button_size.height()) / 2, | 343 (NonClientTopBorderHeight() - settings_button_size.height()) / 2, |
349 info_button_size.width(), | 344 settings_button_size.width(), |
350 info_button_size.height()); | 345 settings_button_size.height()); |
351 | 346 |
352 // Layout the icon. | 347 // Layout the icon. |
353 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; | 348 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; |
354 title_icon_->SetBounds( | 349 title_icon_->SetBounds( |
355 kFrameBorderThickness + kIconSpacing, | 350 kFrameBorderThickness + kIconSpacing, |
356 icon_y, | 351 icon_y, |
357 kIconSize, | 352 kIconSize, |
358 kIconSize); | 353 kIconSize); |
359 | 354 |
360 // Layout the title. | 355 // Layout the title. |
361 int title_x = title_icon_->bounds().right() + kIconSpacing; | 356 int title_x = title_icon_->bounds().right() + kIconSpacing; |
362 int title_height = BrowserFrame::GetTitleFont().GetHeight(); | 357 int title_height = BrowserFrame::GetTitleFont().GetHeight(); |
363 title_label_->SetBounds( | 358 title_label_->SetBounds( |
364 title_x, | 359 title_x, |
365 icon_y + ((kIconSize - title_height - 1) / 2), | 360 icon_y + ((kIconSize - title_height - 1) / 2), |
366 std::max(0, info_button_->x() - kButtonSpacing - title_x), | 361 std::max(0, settings_button_->x() - kButtonSpacing - title_x), |
367 title_height); | 362 title_height); |
368 | 363 |
369 // Calculate the client area bounds. | 364 // Calculate the client area bounds. |
370 int top_height = NonClientTopBorderHeight(); | 365 int top_height = NonClientTopBorderHeight(); |
371 int border_thickness = NonClientBorderThickness(); | 366 int border_thickness = NonClientBorderThickness(); |
372 client_view_bounds_.SetRect( | 367 client_view_bounds_.SetRect( |
373 border_thickness, | 368 border_thickness, |
374 top_height, | 369 top_height, |
375 std::max(0, width() - (2 * border_thickness)), | 370 std::max(0, width() - (2 * border_thickness)), |
376 std::max(0, height() - top_height - border_thickness)); | 371 std::max(0, height() - top_height - border_thickness)); |
(...skipping 24 matching lines...) Expand all Loading... | |
401 void PanelBrowserFrameView::OnMouseCaptureLost() { | 396 void PanelBrowserFrameView::OnMouseCaptureLost() { |
402 if (browser_view_->OnTitleBarMouseCaptureLost()) | 397 if (browser_view_->OnTitleBarMouseCaptureLost()) |
403 return; | 398 return; |
404 BrowserNonClientFrameView::OnMouseCaptureLost(); | 399 BrowserNonClientFrameView::OnMouseCaptureLost(); |
405 } | 400 } |
406 | 401 |
407 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, | 402 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, |
408 const views::Event& event) { | 403 const views::Event& event) { |
409 if (sender == close_button_) | 404 if (sender == close_button_) |
410 frame_->Close(); | 405 frame_->Close(); |
411 else if (sender == info_button_) { | 406 } |
412 gfx::Point origin(info_button_->bounds().origin()); | 407 |
413 views::View::ConvertPointToScreen(this, &origin); | 408 void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { |
414 AboutPanelBubble::Show( | 409 EnsureCreateSettingsMenu(); |
jennb
2011/06/01 23:45:53
usual wording is EnsureSettingsMenuCreated()
| |
415 GetWidget(), | 410 settings_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
416 gfx::Rect(origin, info_button_->bounds().size()), | 411 } |
417 BubbleBorder::BOTTOM_RIGHT, | 412 |
418 GetFaviconForTabIconView(), | 413 bool PanelBrowserFrameView::IsCommandIdChecked(int command_id) const { |
419 browser_view_->browser()); | 414 // Nothing in the menu is checked. |
415 return false; | |
416 } | |
417 | |
418 bool PanelBrowserFrameView::IsCommandIdEnabled(int command_id) const { | |
419 const Extension* extension = GetExtension(); | |
420 if (!extension) | |
421 return false; | |
422 | |
423 switch (command_id) { | |
424 case COMMAND_NAME: | |
425 // The NAME links to the Homepage URL. If the extension doesn't have a | |
426 // homepage, we just disable this menu item. | |
427 return extension->GetHomepageURL().is_valid(); | |
428 case COMMAND_CONFIGURE: | |
429 return extension->options_url().spec().length() > 0; | |
430 case COMMAND_DISABLE: | |
431 case COMMAND_UNINSTALL: | |
432 // Some extension types can not be disabled or uninstalled. | |
433 return Extension::UserMayDisable(extension->location()); | |
434 case COMMAND_MANAGE: | |
435 return true; | |
436 default: | |
437 NOTREACHED(); | |
438 return false; | |
439 } | |
440 } | |
441 | |
442 bool PanelBrowserFrameView::GetAcceleratorForCommandId( | |
443 int command_id, ui::Accelerator* accelerator) { | |
444 return false; | |
445 } | |
446 | |
447 void PanelBrowserFrameView::ExecuteCommand(int command_id) { | |
448 const Extension* extension = GetExtension(); | |
449 if (!extension) | |
450 return; | |
451 | |
452 Browser* browser = browser_view_->browser(); | |
453 switch (command_id) { | |
454 case COMMAND_NAME: | |
455 browser->OpenURL(extension->GetHomepageURL(), | |
456 GURL(), | |
457 NEW_FOREGROUND_TAB, | |
458 PageTransition::LINK); | |
459 break; | |
460 case COMMAND_CONFIGURE: | |
461 DCHECK(!extension->options_url().is_empty()); | |
462 browser->GetProfile()->GetExtensionProcessManager()->OpenOptionsPage( | |
463 extension, browser); | |
464 break; | |
465 case COMMAND_DISABLE: | |
466 browser->GetProfile()->GetExtensionService()->DisableExtension( | |
467 extension->id()); | |
468 break; | |
469 case COMMAND_UNINSTALL: | |
470 // TODO(jianli): Need to handle the case that the extension API requests | |
471 // the panel to be closed when the uninstall dialog is still showing. | |
472 extension_uninstall_dialog_.reset(new ExtensionUninstallDialog( | |
473 browser->GetProfile())); | |
474 extension_uninstall_dialog_->ConfirmUninstall(this, extension); | |
475 break; | |
476 case COMMAND_MANAGE: | |
477 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), | |
478 GURL(), | |
479 SINGLETON_TAB, | |
480 PageTransition::LINK); | |
481 break; | |
482 default: | |
483 NOTREACHED(); | |
484 break; | |
420 } | 485 } |
421 } | 486 } |
422 | 487 |
423 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { | 488 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { |
424 // This function is queried during the creation of the window as the | 489 // This function is queried during the creation of the window as the |
425 // TabIconView we host is initialized, so we need to NULL check the selected | 490 // TabIconView we host is initialized, so we need to NULL check the selected |
426 // TabContents because in this condition there is not yet a selected tab. | 491 // TabContents because in this condition there is not yet a selected tab. |
427 TabContents* current_tab = browser_view_->GetSelectedTabContents(); | 492 TabContents* current_tab = browser_view_->GetSelectedTabContents(); |
428 return current_tab ? current_tab->is_loading() : false; | 493 return current_tab ? current_tab->is_loading() : false; |
429 } | 494 } |
430 | 495 |
431 SkBitmap PanelBrowserFrameView::GetFaviconForTabIconView() { | 496 SkBitmap PanelBrowserFrameView::GetFaviconForTabIconView() { |
432 return frame_->window_delegate()->GetWindowIcon(); | 497 return frame_->window_delegate()->GetWindowIcon(); |
433 } | 498 } |
434 | 499 |
500 void PanelBrowserFrameView::ExtensionDialogAccepted() { | |
501 const Extension* extension = GetExtension(); | |
502 if (extension) { | |
503 browser_view_->browser()->GetProfile()->GetExtensionService()-> | |
504 UninstallExtension(extension->id(), false, NULL); | |
505 } | |
506 } | |
507 | |
508 void PanelBrowserFrameView::ExtensionDialogCanceled() { | |
509 } | |
510 | |
435 int PanelBrowserFrameView::NonClientBorderThickness() const { | 511 int PanelBrowserFrameView::NonClientBorderThickness() const { |
436 return kFrameBorderThickness + kClientEdgeThickness; | 512 return kFrameBorderThickness + kClientEdgeThickness; |
437 } | 513 } |
438 | 514 |
439 int PanelBrowserFrameView::NonClientTopBorderHeight() const { | 515 int PanelBrowserFrameView::NonClientTopBorderHeight() const { |
440 return kFrameBorderThickness + kTitleBarHeight + kClientEdgeThickness; | 516 return kFrameBorderThickness + kTitleBarHeight + kClientEdgeThickness; |
441 } | 517 } |
442 | 518 |
443 void PanelBrowserFrameView::UpdateControlStyles(PaintState paint_state) { | 519 void PanelBrowserFrameView::UpdateControlStyles(PaintState paint_state) { |
444 DCHECK(paint_state != NOT_PAINTED); | 520 DCHECK(paint_state != NOT_PAINTED); |
445 | 521 |
446 if (paint_state == paint_state_) | 522 if (paint_state == paint_state_) |
447 return; | 523 return; |
448 paint_state_ = paint_state; | 524 paint_state_ = paint_state; |
449 | 525 |
450 // For now, the only indication is whether the font is bold or not. | 526 SkColor title_color = GetThemeProvider()-> |
527 GetColor(paint_state == PAINT_AS_ACTIVE ? | |
528 ThemeService::COLOR_TAB_TEXT : | |
529 ThemeService::COLOR_BACKGROUND_TAB_TEXT); | |
530 title_label_->SetColor(title_color); | |
451 title_label_->SetFont( | 531 title_label_->SetFont( |
452 paint_state == PAINT_AS_ACTIVE ? *active_font : *inactive_font); | 532 paint_state == PAINT_AS_ACTIVE ? *active_font : *inactive_font); |
533 | |
534 close_button_->SetBackground(title_color, | |
535 close_button_resources.normal_image, | |
536 close_button_resources.mask_image); | |
453 } | 537 } |
454 | 538 |
455 void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) { | 539 void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) { |
456 SkBitmap* theme_frame = GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR); | 540 SkBitmap* theme_frame = GetThemeProvider()->GetBitmapNamed( |
541 (paint_state_ == PAINT_AS_ACTIVE) ? IDR_THEME_TOOLBAR | |
542 : IDR_THEME_TAB_BACKGROUND); | |
457 | 543 |
458 // Draw the theme frame. | 544 // Draw the theme frame. |
459 canvas->TileImageInt(*theme_frame, 0, 0, width(), height()); | 545 canvas->TileImageInt(*theme_frame, 0, 0, width(), height()); |
460 | 546 |
461 // Draw the top border. | 547 // Draw the top border. |
462 canvas->DrawBitmapInt(*(frame_edges.top_left), 0, 0); | 548 canvas->DrawBitmapInt(*(frame_edges.top_left), 0, 0); |
463 canvas->TileImageInt( | 549 canvas->TileImageInt( |
464 *(frame_edges.top), frame_edges.top_left->width(), 0, | 550 *(frame_edges.top), frame_edges.top_left->width(), 0, |
465 width() - frame_edges.top_right->width(), frame_edges.top->height()); | 551 width() - frame_edges.top_right->width(), frame_edges.top->height()); |
466 canvas->DrawBitmapInt( | 552 canvas->DrawBitmapInt( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 client_view_bounds_.x() - client_edges.left->width(), | 624 client_view_bounds_.x() - client_edges.left->width(), |
539 client_area_top, client_edges.left->width(), client_area_height); | 625 client_area_top, client_edges.left->width(), client_area_height); |
540 } | 626 } |
541 | 627 |
542 void PanelBrowserFrameView::UpdateTitleBar() { | 628 void PanelBrowserFrameView::UpdateTitleBar() { |
543 title_label_->SetText( | 629 title_label_->SetText( |
544 frame_->window_delegate()->GetWindowTitle()); | 630 frame_->window_delegate()->GetWindowTitle()); |
545 } | 631 } |
546 | 632 |
547 void PanelBrowserFrameView::OnActivationChanged(bool active) { | 633 void PanelBrowserFrameView::OnActivationChanged(bool active) { |
548 UpdateInfoButtonVisibility(active, mouse_watcher_->IsCursorInViewBounds()); | 634 UpdateSettingsButtonVisibility(active, |
635 mouse_watcher_->IsCursorInViewBounds()); | |
549 SchedulePaint(); | 636 SchedulePaint(); |
550 } | 637 } |
551 | 638 |
552 void PanelBrowserFrameView::OnMouseEnterOrLeaveWindow(bool mouse_entered) { | 639 void PanelBrowserFrameView::OnMouseEnterOrLeaveWindow(bool mouse_entered) { |
553 UpdateInfoButtonVisibility(browser_view_->panel()->IsActive(), | 640 // Panel might be closed when we still watch the mouse event. |
554 mouse_entered); | 641 if (!browser_view_->panel()) |
642 return; | |
643 UpdateSettingsButtonVisibility(browser_view_->panel()->IsActive(), | |
644 mouse_entered); | |
555 } | 645 } |
556 | 646 |
557 void PanelBrowserFrameView::UpdateInfoButtonVisibility(bool active, | 647 void PanelBrowserFrameView::UpdateSettingsButtonVisibility( |
558 bool cursor_in_view) { | 648 bool active, bool cursor_in_view) { |
559 info_button_->SetVisible(active || cursor_in_view); | 649 settings_button_->SetVisible(active || cursor_in_view); |
560 } | 650 } |
651 | |
652 const Extension* PanelBrowserFrameView::GetExtension() const { | |
653 return Panel::GetExtension(browser_view_->browser()); | |
654 } | |
655 | |
656 void PanelBrowserFrameView::EnsureCreateSettingsMenu() { | |
657 if (settings_menu_.get()) | |
658 return; | |
659 | |
660 const Extension* extension = GetExtension(); | |
661 if (!extension) | |
662 return; | |
663 | |
664 settings_menu_contents_.reset(new ui::SimpleMenuModel(this)); | |
665 | |
666 settings_menu_contents_->AddItem( | |
667 COMMAND_NAME, UTF8ToUTF16(extension->name())); | |
668 settings_menu_contents_->AddSeparator(); | |
669 settings_menu_contents_->AddItem( | |
670 COMMAND_CONFIGURE, l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS)); | |
671 settings_menu_contents_->AddItem( | |
672 COMMAND_DISABLE, l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); | |
673 settings_menu_contents_->AddItem( | |
674 COMMAND_UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | |
675 settings_menu_contents_->AddSeparator(); | |
676 settings_menu_contents_->AddItem( | |
677 COMMAND_MANAGE, l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS)); | |
678 | |
679 settings_menu_.reset(new views::Menu2(settings_menu_contents_.get())); | |
680 } | |
OLD | NEW |