OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/frame/glass_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // buttons, but the space will look cluttered if it actually slides under them, | 57 // buttons, but the space will look cluttered if it actually slides under them, |
58 // so we stop it when the gap between the two is down to 5 px. | 58 // so we stop it when the gap between the two is down to 5 px. |
59 const int kNewTabCaptionRestoredSpacing = 5; | 59 const int kNewTabCaptionRestoredSpacing = 5; |
60 // In maximized mode, where the New Tab button and the caption buttons are at | 60 // In maximized mode, where the New Tab button and the caption buttons are at |
61 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 61 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
62 // looking too cluttered. | 62 // looking too cluttered. |
63 const int kNewTabCaptionMaximizedSpacing = 16; | 63 const int kNewTabCaptionMaximizedSpacing = 16; |
64 | 64 |
65 // Converts the |image| to a Windows icon and returns the corresponding HICON | 65 // Converts the |image| to a Windows icon and returns the corresponding HICON |
66 // handle. |image| is resized to desired |width| and |height| if needed. | 66 // handle. |image| is resized to desired |width| and |height| if needed. |
67 HICON CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia& image, | 67 base::win::ScopedHICON CreateHICONFromSkBitmapSizedTo( |
68 int width, | 68 const gfx::ImageSkia& image, |
69 int height) { | 69 int width, |
70 if (width == image.width() && height == image.height()) | 70 int height) { |
71 return IconUtil::CreateHICONFromSkBitmap(*image.bitmap()); | 71 return base::win::ScopedHICON(IconUtil::CreateHICONFromSkBitmap( |
72 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize( | 72 width == image.width() && height == image.height() |
73 *image.bitmap(), skia::ImageOperations::RESIZE_BEST, width, height)); | 73 ? *image.bitmap() |
| 74 : skia::ImageOperations::Resize(*image.bitmap(), |
| 75 skia::ImageOperations::RESIZE_BEST, |
| 76 width, height))); |
74 } | 77 } |
75 | 78 |
76 } // namespace | 79 } // namespace |
77 | 80 |
78 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
79 // GlassBrowserFrameView, public: | 82 // GlassBrowserFrameView, public: |
80 | 83 |
81 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, | 84 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, |
82 BrowserView* browser_view) | 85 BrowserView* browser_view) |
83 : BrowserNonClientFrameView(frame, browser_view), | 86 : BrowserNonClientFrameView(frame, browser_view), |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (throbber_running_) { | 577 if (throbber_running_) { |
575 throbber_running_ = false; | 578 throbber_running_ = false; |
576 | 579 |
577 HICON small_icon = nullptr; | 580 HICON small_icon = nullptr; |
578 HICON big_icon = nullptr; | 581 HICON big_icon = nullptr; |
579 | 582 |
580 // Check if hosted BrowserView has a window icon to use. | 583 // Check if hosted BrowserView has a window icon to use. |
581 if (browser_view()->ShouldShowWindowIcon()) { | 584 if (browser_view()->ShouldShowWindowIcon()) { |
582 gfx::ImageSkia icon = browser_view()->GetWindowIcon(); | 585 gfx::ImageSkia icon = browser_view()->GetWindowIcon(); |
583 if (!icon.isNull()) { | 586 if (!icon.isNull()) { |
584 small_icon = CreateHICONFromSkBitmapSizedTo( | 587 // Take responsibility for eventually destroying the created icons. |
585 icon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); | 588 small_window_icon_ = |
586 big_icon = CreateHICONFromSkBitmapSizedTo( | 589 CreateHICONFromSkBitmapSizedTo(icon, GetSystemMetrics(SM_CXSMICON), |
587 icon, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); | 590 GetSystemMetrics(SM_CYSMICON)) |
| 591 .Pass(); |
| 592 big_window_icon_ = |
| 593 CreateHICONFromSkBitmapSizedTo(icon, GetSystemMetrics(SM_CXICON), |
| 594 GetSystemMetrics(SM_CYICON)) |
| 595 .Pass(); |
| 596 |
| 597 small_icon = small_window_icon_.Get(); |
| 598 big_icon = big_window_icon_.Get(); |
588 } | 599 } |
589 } | 600 } |
590 | 601 |
591 // Fallback to class icon. | 602 // Fallback to class icon. |
592 if (!small_icon) { | 603 if (!small_icon) { |
593 small_icon = reinterpret_cast<HICON>( | 604 small_icon = reinterpret_cast<HICON>( |
594 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICONSM)); | 605 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICONSM)); |
595 } | 606 } |
596 if (!big_icon) { | 607 if (!big_icon) { |
597 big_icon = reinterpret_cast<HICON>( | 608 big_icon = reinterpret_cast<HICON>( |
598 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICON)); | 609 GetClassLongPtr(views::HWNDForWidget(frame()), GCLP_HICON)); |
599 } | 610 } |
600 | 611 |
601 // This will reset the icon which we set in the throbber code. | 612 // This will reset the icon which we set in the throbber code. |
602 // WM_SETICON with null icon restores the icon for title bar but not | 613 // WM_SETICON with null icon restores the icon for title bar but not |
603 // for taskbar. See http://crbug.com/29996 | 614 // for taskbar. See http://crbug.com/29996 |
604 HICON previous_small_icon = reinterpret_cast<HICON>( | 615 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, |
605 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, | 616 static_cast<WPARAM>(ICON_SMALL), |
606 static_cast<WPARAM>(ICON_SMALL), | 617 reinterpret_cast<LPARAM>(small_icon)); |
607 reinterpret_cast<LPARAM>(small_icon))); | |
608 | 618 |
609 HICON previous_big_icon = reinterpret_cast<HICON>( | 619 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, |
610 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, | 620 static_cast<WPARAM>(ICON_BIG), |
611 static_cast<WPARAM>(ICON_BIG), | 621 reinterpret_cast<LPARAM>(big_icon)); |
612 reinterpret_cast<LPARAM>(big_icon))); | |
613 | |
614 if (previous_small_icon) | |
615 ::DestroyIcon(previous_small_icon); | |
616 | |
617 if (previous_big_icon) | |
618 ::DestroyIcon(previous_big_icon); | |
619 } | 622 } |
620 } | 623 } |
621 | 624 |
622 void GlassBrowserFrameView::DisplayNextThrobberFrame() { | 625 void GlassBrowserFrameView::DisplayNextThrobberFrame() { |
623 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; | 626 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; |
624 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, | 627 SendMessage(views::HWNDForWidget(frame()), WM_SETICON, |
625 static_cast<WPARAM>(ICON_SMALL), | 628 static_cast<WPARAM>(ICON_SMALL), |
626 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); | 629 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); |
627 } | 630 } |
628 | 631 |
629 // static | 632 // static |
630 void GlassBrowserFrameView::InitThrobberIcons() { | 633 void GlassBrowserFrameView::InitThrobberIcons() { |
631 static bool initialized = false; | 634 static bool initialized = false; |
632 if (!initialized) { | 635 if (!initialized) { |
633 for (int i = 0; i < kThrobberIconCount; ++i) { | 636 for (int i = 0; i < kThrobberIconCount; ++i) { |
634 throbber_icons_[i] = | 637 throbber_icons_[i] = |
635 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 638 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
636 DCHECK(throbber_icons_[i]); | 639 DCHECK(throbber_icons_[i]); |
637 } | 640 } |
638 initialized = true; | 641 initialized = true; |
639 } | 642 } |
640 } | 643 } |
OLD | NEW |