Chromium Code Reviews| 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" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
| 10 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 // The spacing in pixels between the icon and the border/text. | 45 // The spacing in pixels between the icon and the border/text. |
| 46 const int kIconSpacing = 4; | 46 const int kIconSpacing = 4; |
| 47 | 47 |
| 48 // The height and width in pixels of the icon. | 48 // The height and width in pixels of the icon. |
| 49 const int kIconSize = 16; | 49 const int kIconSize = 16; |
| 50 | 50 |
| 51 // The spacing in pixels between buttons or the button and the adjacent control. | 51 // The spacing in pixels between buttons or the button and the adjacent control. |
| 52 const int kButtonSpacing = 6; | 52 const int kButtonSpacing = 6; |
| 53 | 53 |
| 54 // The panel can be minimized to 3-pixel lines. | |
| 55 const int kMinimizedPanelHeight = 3; | |
| 56 | |
| 54 // Colors used in painting the titlebar for drawing attention. | 57 // Colors used in painting the titlebar for drawing attention. |
| 55 const SkColor kBackgroundColorForAttention = 0xfffa983a; | 58 const SkColor kBackgroundColorForAttention = 0xfffa983a; |
| 56 const SkColor kTitleTextColorForAttention = SK_ColorWHITE; | 59 const SkColor kTitleTextColorForAttention = SK_ColorWHITE; |
| 57 | 60 |
| 58 struct ButtonResources { | 61 struct ButtonResources { |
| 59 SkBitmap* normal_image; | 62 SkBitmap* normal_image; |
| 60 SkBitmap* mask_image; | 63 SkBitmap* mask_image; |
| 61 SkBitmap* hover_image; | 64 SkBitmap* hover_image; |
| 62 SkBitmap* pushed_image; | 65 SkBitmap* pushed_image; |
| 63 | 66 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 93 bottom = rb.GetBitmapNamed(bottom_id); | 96 bottom = rb.GetBitmapNamed(bottom_id); |
| 94 bottom_left = rb.GetBitmapNamed(bottom_left_id); | 97 bottom_left = rb.GetBitmapNamed(bottom_left_id); |
| 95 left = rb.GetBitmapNamed(left_id); | 98 left = rb.GetBitmapNamed(left_id); |
| 96 } | 99 } |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 ButtonResources settings_button_resources; | 102 ButtonResources settings_button_resources; |
| 100 ButtonResources close_button_resources; | 103 ButtonResources close_button_resources; |
| 101 EdgeResources frame_edges; | 104 EdgeResources frame_edges; |
| 102 EdgeResources client_edges; | 105 EdgeResources client_edges; |
| 103 gfx::Font* active_font = NULL; | 106 gfx::Font* title_font = NULL; |
| 104 gfx::Font* inactive_font = NULL; | |
| 105 SkBitmap* background_bitmap_for_attention = NULL; | 107 SkBitmap* background_bitmap_for_attention = NULL; |
| 106 | 108 |
| 107 void LoadImageResources() { | 109 void LoadImageResources() { |
| 108 settings_button_resources.SetResources( | 110 settings_button_resources.SetResources( |
| 109 IDR_BALLOON_WRENCH, 0, IDR_BALLOON_WRENCH_H, IDR_BALLOON_WRENCH_P); | 111 IDR_BALLOON_WRENCH, 0, IDR_BALLOON_WRENCH_H, IDR_BALLOON_WRENCH_P); |
| 110 | 112 |
| 111 close_button_resources.SetResources( | 113 close_button_resources.SetResources( |
| 112 IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); | 114 IDR_TAB_CLOSE, IDR_TAB_CLOSE_MASK, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE_P); |
| 113 | 115 |
| 114 frame_edges.SetResources( | 116 frame_edges.SetResources( |
| 115 IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_CENTER, | 117 IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_CENTER, |
| 116 IDR_WINDOW_TOP_RIGHT_CORNER, IDR_WINDOW_RIGHT_SIDE, | 118 IDR_WINDOW_TOP_RIGHT_CORNER, IDR_WINDOW_RIGHT_SIDE, |
| 117 IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_BOTTOM_CENTER, | 119 IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_BOTTOM_CENTER, |
| 118 IDR_WINDOW_BOTTOM_LEFT_CORNER, IDR_WINDOW_LEFT_SIDE); | 120 IDR_WINDOW_BOTTOM_LEFT_CORNER, IDR_WINDOW_LEFT_SIDE); |
| 119 | 121 |
| 120 client_edges.SetResources( | 122 client_edges.SetResources( |
| 121 IDR_APP_TOP_LEFT, IDR_APP_TOP_CENTER, | 123 IDR_APP_TOP_LEFT, IDR_APP_TOP_CENTER, |
| 122 IDR_APP_TOP_RIGHT, IDR_CONTENT_RIGHT_SIDE, | 124 IDR_APP_TOP_RIGHT, IDR_CONTENT_RIGHT_SIDE, |
| 123 IDR_CONTENT_BOTTOM_RIGHT_CORNER, IDR_CONTENT_BOTTOM_CENTER, | 125 IDR_CONTENT_BOTTOM_RIGHT_CORNER, IDR_CONTENT_BOTTOM_CENTER, |
| 124 IDR_CONTENT_BOTTOM_LEFT_CORNER, IDR_CONTENT_LEFT_SIDE); | 126 IDR_CONTENT_BOTTOM_LEFT_CORNER, IDR_CONTENT_LEFT_SIDE); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void EnsureResourcesInitialized() { | 129 void EnsureResourcesInitialized() { |
| 128 static bool resources_initialized = false; | 130 static bool resources_initialized = false; |
| 129 if (resources_initialized) | 131 if (resources_initialized) |
| 130 return; | 132 return; |
| 131 resources_initialized = true; | 133 resources_initialized = true; |
| 132 | 134 |
| 133 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 135 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 134 active_font = new gfx::Font(rb.GetFont(ResourceBundle::BoldFont)); | 136 title_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); |
| 135 inactive_font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); | |
| 136 | 137 |
| 137 // Creates a bitmap of the specified color. | 138 // Creates a bitmap of the specified color. |
| 138 background_bitmap_for_attention = new SkBitmap(); | 139 background_bitmap_for_attention = new SkBitmap(); |
| 139 background_bitmap_for_attention->setConfig( | 140 background_bitmap_for_attention->setConfig( |
| 140 SkBitmap::kARGB_8888_Config, 16, 16); | 141 SkBitmap::kARGB_8888_Config, 16, 16); |
| 141 background_bitmap_for_attention->allocPixels(); | 142 background_bitmap_for_attention->allocPixels(); |
| 142 background_bitmap_for_attention->eraseColor(kBackgroundColorForAttention); | 143 background_bitmap_for_attention->eraseColor(kBackgroundColorForAttention); |
| 143 | 144 |
| 144 LoadImageResources(); | 145 LoadImageResources(); |
| 145 } | 146 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 349 } |
| 349 | 350 |
| 350 gfx::Size PanelBrowserFrameView::GetMinimumSize() { | 351 gfx::Size PanelBrowserFrameView::GetMinimumSize() { |
| 351 // This makes the panel be able to shrink to very small, like 3-pixel lines. | 352 // This makes the panel be able to shrink to very small, like 3-pixel lines. |
| 352 // Since the panel cannot be resized by the user, we do not need to enforce | 353 // Since the panel cannot be resized by the user, we do not need to enforce |
| 353 // the minimum size. | 354 // the minimum size. |
| 354 return gfx::Size(); | 355 return gfx::Size(); |
| 355 } | 356 } |
| 356 | 357 |
| 357 void PanelBrowserFrameView::Layout() { | 358 void PanelBrowserFrameView::Layout() { |
| 358 // If the panel height is smaller than the title-bar height, as in minimized | |
| 359 // case, we hide all controls. | |
| 360 bool is_control_visible = height() >= kTitlebarHeight; | |
| 361 close_button_->SetVisible(is_control_visible); | |
| 362 settings_button_->SetVisible( | |
| 363 is_control_visible && is_settings_button_visible_); | |
| 364 title_icon_->SetVisible(is_control_visible); | |
| 365 title_label_->SetVisible(is_control_visible); | |
| 366 | |
| 367 // Layout the close button. | 359 // Layout the close button. |
| 368 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 360 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 369 close_button_->SetBounds( | 361 close_button_->SetBounds( |
| 370 width() - kFrameBorderThickness - kButtonSpacing - | 362 width() - kFrameBorderThickness - kButtonSpacing - |
| 371 close_button_size.width(), | 363 close_button_size.width(), |
| 372 (NonClientTopBorderHeight() - close_button_size.height()) / 2, | 364 (NonClientTopBorderHeight() - close_button_size.height()) / 2, |
| 373 close_button_size.width(), | 365 close_button_size.width(), |
| 374 close_button_size.height()); | 366 close_button_size.height()); |
| 375 | 367 |
| 376 // Layout the settings button. | 368 // Layout the settings button. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 } | 546 } |
| 555 | 547 |
| 556 int PanelBrowserFrameView::NonClientBorderThickness() const { | 548 int PanelBrowserFrameView::NonClientBorderThickness() const { |
| 557 return kFrameBorderThickness + kClientEdgeThickness; | 549 return kFrameBorderThickness + kClientEdgeThickness; |
| 558 } | 550 } |
| 559 | 551 |
| 560 int PanelBrowserFrameView::NonClientTopBorderHeight() const { | 552 int PanelBrowserFrameView::NonClientTopBorderHeight() const { |
| 561 return kFrameBorderThickness + kTitlebarHeight + kClientEdgeThickness; | 553 return kFrameBorderThickness + kTitlebarHeight + kClientEdgeThickness; |
| 562 } | 554 } |
| 563 | 555 |
| 556 int PanelBrowserFrameView::MinimizedPanelHeight() { | |
| 557 return kMinimizedPanelHeight; | |
| 558 } | |
| 559 | |
| 564 SkColor PanelBrowserFrameView::GetTitleColor(PaintState paint_state) const { | 560 SkColor PanelBrowserFrameView::GetTitleColor(PaintState paint_state) const { |
| 565 switch (paint_state) { | 561 switch (paint_state) { |
| 566 case PAINT_AS_INACTIVE: | 562 case PAINT_AS_INACTIVE: |
| 567 return GetThemeProvider()->GetColor( | 563 return GetThemeProvider()->GetColor( |
| 568 ThemeService::COLOR_BACKGROUND_TAB_TEXT); | 564 ThemeService::COLOR_BACKGROUND_TAB_TEXT); |
| 569 case PAINT_AS_ACTIVE: | 565 case PAINT_AS_ACTIVE: |
| 570 return GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT); | 566 return GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT); |
| 571 case PAINT_FOR_ATTENTION: | 567 case PAINT_FOR_ATTENTION: |
| 572 return kTitleTextColorForAttention; | 568 return kTitleTextColorForAttention; |
| 573 default: | 569 default: |
| 574 NOTREACHED(); | 570 NOTREACHED(); |
| 575 return SkColor(); | 571 return SkColor(); |
| 576 } | 572 } |
| 577 } | 573 } |
| 578 | 574 |
| 579 gfx::Font* PanelBrowserFrameView::GetTitleFont(PaintState paint_state) const { | 575 gfx::Font* PanelBrowserFrameView::GetTitleFont(PaintState paint_state) const { |
|
jennb
2011/08/17 23:01:35
Should we change this method to not take paint_sta
| |
| 580 switch (paint_state) { | 576 return title_font; |
| 581 case PAINT_AS_INACTIVE: | |
| 582 case PAINT_FOR_ATTENTION: | |
| 583 return inactive_font; | |
| 584 case PAINT_AS_ACTIVE: | |
| 585 return active_font; | |
| 586 default: | |
| 587 NOTREACHED(); | |
| 588 return NULL; | |
| 589 } | |
| 590 } | 577 } |
| 591 | 578 |
| 592 SkBitmap* PanelBrowserFrameView::GetFrameTheme(PaintState paint_state) const { | 579 SkBitmap* PanelBrowserFrameView::GetFrameTheme(PaintState paint_state) const { |
| 593 switch (paint_state) { | 580 switch (paint_state) { |
| 594 case PAINT_AS_INACTIVE: | 581 case PAINT_AS_INACTIVE: |
| 595 return GetThemeProvider()->GetBitmapNamed(IDR_THEME_TAB_BACKGROUND); | 582 return GetThemeProvider()->GetBitmapNamed(IDR_THEME_TAB_BACKGROUND); |
| 596 case PAINT_AS_ACTIVE: | 583 case PAINT_AS_ACTIVE: |
| 597 return GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR); | 584 return GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR); |
| 598 case PAINT_FOR_ATTENTION: | 585 case PAINT_FOR_ATTENTION: |
| 599 return background_bitmap_for_attention; | 586 return background_bitmap_for_attention; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 618 close_button_resources.normal_image, | 605 close_button_resources.normal_image, |
| 619 close_button_resources.mask_image); | 606 close_button_resources.mask_image); |
| 620 } | 607 } |
| 621 | 608 |
| 622 void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) { | 609 void PanelBrowserFrameView::PaintFrameBorder(gfx::Canvas* canvas) { |
| 623 SkBitmap* theme_frame = GetFrameTheme(paint_state_); | 610 SkBitmap* theme_frame = GetFrameTheme(paint_state_); |
| 624 | 611 |
| 625 // Draw the theme frame. | 612 // Draw the theme frame. |
| 626 canvas->TileImageInt(*theme_frame, 0, 0, width(), height()); | 613 canvas->TileImageInt(*theme_frame, 0, 0, width(), height()); |
| 627 | 614 |
| 615 // No need to paint other stuffs if panel is minimized. | |
|
jennb
2011/08/17 23:01:35
s/stuffs/stuff
| |
| 616 if (height() <= kMinimizedPanelHeight) | |
| 617 return; | |
| 618 | |
| 628 // Draw the top border. | 619 // Draw the top border. |
| 629 canvas->DrawBitmapInt(*(frame_edges.top_left), 0, 0); | 620 canvas->DrawBitmapInt(*(frame_edges.top_left), 0, 0); |
| 630 canvas->TileImageInt( | 621 canvas->TileImageInt( |
| 631 *(frame_edges.top), frame_edges.top_left->width(), 0, | 622 *(frame_edges.top), frame_edges.top_left->width(), 0, |
| 632 width() - frame_edges.top_right->width(), frame_edges.top->height()); | 623 width() - frame_edges.top_right->width(), frame_edges.top->height()); |
| 633 canvas->DrawBitmapInt( | 624 canvas->DrawBitmapInt( |
| 634 *(frame_edges.top_right), | 625 *(frame_edges.top_right), |
| 635 width() - frame_edges.top_right->width(), 0); | 626 width() - frame_edges.top_right->width(), 0); |
| 636 | 627 |
| 637 // Draw the right border. | 628 // Draw the right border. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 660 canvas->TileImageInt( | 651 canvas->TileImageInt( |
| 661 *(frame_edges.left), 0, frame_edges.top_left->height(), | 652 *(frame_edges.left), 0, frame_edges.top_left->height(), |
| 662 frame_edges.left->width(), | 653 frame_edges.left->width(), |
| 663 height() - frame_edges.top_left->height() - | 654 height() - frame_edges.top_left->height() - |
| 664 frame_edges.bottom_left->height()); | 655 frame_edges.bottom_left->height()); |
| 665 } | 656 } |
| 666 | 657 |
| 667 void PanelBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) { | 658 void PanelBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) { |
| 668 int client_area_top = client_view_bounds_.y(); | 659 int client_area_top = client_view_bounds_.y(); |
| 669 | 660 |
| 661 // No need to paint other stuffs if panel is minimized. | |
|
jennb
2011/08/17 23:01:35
Ditto.
| |
| 662 if (height() <= kMinimizedPanelHeight) | |
| 663 return; | |
| 664 | |
| 670 // Draw the top edge. | 665 // Draw the top edge. |
| 671 int top_edge_y = client_area_top - client_edges.top->height(); | 666 int top_edge_y = client_area_top - client_edges.top->height(); |
| 672 canvas->DrawBitmapInt( | 667 canvas->DrawBitmapInt( |
| 673 *(client_edges.top_left), | 668 *(client_edges.top_left), |
| 674 client_view_bounds_.x() - client_edges.top_left->width(), | 669 client_view_bounds_.x() - client_edges.top_left->width(), |
| 675 top_edge_y); | 670 top_edge_y); |
| 676 canvas->TileImageInt( | 671 canvas->TileImageInt( |
| 677 *(client_edges.top), client_view_bounds_.x(), top_edge_y, | 672 *(client_edges.top), client_view_bounds_.x(), top_edge_y, |
| 678 client_view_bounds_.width(), client_edges.top->height()); | 673 client_view_bounds_.width(), client_edges.top->height()); |
| 679 canvas->DrawBitmapInt( | 674 canvas->DrawBitmapInt( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 settings_menu_contents_.AddItem( | 745 settings_menu_contents_.AddItem( |
| 751 COMMAND_DISABLE, l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); | 746 COMMAND_DISABLE, l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); |
| 752 settings_menu_contents_.AddItem( | 747 settings_menu_contents_.AddItem( |
| 753 COMMAND_UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | 748 COMMAND_UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| 754 settings_menu_contents_.AddSeparator(); | 749 settings_menu_contents_.AddSeparator(); |
| 755 settings_menu_contents_.AddItem( | 750 settings_menu_contents_.AddItem( |
| 756 COMMAND_MANAGE, l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS)); | 751 COMMAND_MANAGE, l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS)); |
| 757 | 752 |
| 758 settings_menu_adapter_.BuildMenu(&settings_menu_); | 753 settings_menu_adapter_.BuildMenu(&settings_menu_); |
| 759 } | 754 } |
| OLD | NEW |