| 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 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/command_updater.h" | 8 #include "chrome/browser/command_updater.h" |
| 9 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 9 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 10 #import "chrome/browser/ui/cocoa/themed_window.h" | 10 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "grit/components_strings.h" | 12 #include "grit/components_strings.h" |
| 13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util_mac.h" | 14 #include "ui/base/l10n/l10n_util_mac.h" |
| 15 #include "ui/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
| 16 #include "ui/gfx/color_palette.h" | 16 #include "ui/gfx/color_palette.h" |
| 17 #include "ui/gfx/image/image_skia_util_mac.h" | |
| 18 #include "ui/gfx/paint_vector_icon.h" | |
| 19 #include "ui/gfx/vector_icons_public.h" | |
| 20 | 17 |
| 21 namespace { | 18 namespace { |
| 22 | 19 |
| 23 // The info-bubble point should look like it points to the point | 20 // The info-bubble point should look like it points to the point |
| 24 // between the star's lower tips. The popup should be where the | 21 // between the star's lower tips. The popup should be where the |
| 25 // Omnibox popup ends up (2px below field). Determined via Pixie.app | 22 // Omnibox popup ends up (2px below field). Determined via Pixie.app |
| 26 // magnification. | 23 // magnification. |
| 27 const CGFloat kStarPointYOffset = 2.0; | 24 const CGFloat kStarPointYOffset = 2.0; |
| 28 | 25 |
| 29 } // namespace | 26 } // namespace |
| 30 | 27 |
| 31 StarDecoration::StarDecoration(CommandUpdater* command_updater) | 28 StarDecoration::StarDecoration(CommandUpdater* command_updater) |
| 32 : command_updater_(command_updater) { | 29 : command_updater_(command_updater) { |
| 33 SetVisible(true); | 30 SetVisible(true); |
| 34 SetStarred(false, false); | 31 SetStarred(false, false); |
| 35 } | 32 } |
| 36 | 33 |
| 37 StarDecoration::~StarDecoration() { | 34 StarDecoration::~StarDecoration() { |
| 38 } | 35 } |
| 39 | 36 |
| 40 void StarDecoration::SetStarred(bool starred, bool locationBarIsDark) { | 37 void StarDecoration::SetStarred(bool starred, bool location_bar_is_dark) { |
| 41 starred_ = starred; | 38 starred_ = starred; |
| 42 const int image_id = starred ? IDR_STAR_LIT : IDR_STAR; | |
| 43 const int tip_id = starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR; | 39 const int tip_id = starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR; |
| 44 if (ui::MaterialDesignController::IsModeMaterial()) { | 40 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 45 NSImage* theImage; | 41 const int image_id = starred ? IDR_STAR_LIT : IDR_STAR; |
| 46 gfx::VectorIconId iconId = starred_ ? | |
| 47 gfx::VectorIconId::LOCATION_BAR_STAR_ACTIVE : | |
| 48 gfx::VectorIconId::LOCATION_BAR_STAR; | |
| 49 SkColor starColor = gfx::kPlaceholderColor; | |
| 50 if (locationBarIsDark) { | |
| 51 starColor = SK_ColorWHITE; | |
| 52 } else if (starred_) { | |
| 53 starColor = gfx::kGoogleBlue500; | |
| 54 } else { | |
| 55 starColor = gfx::kChromeIconGrey; | |
| 56 } | |
| 57 theImage = NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 58 iconId, 16, starColor)); | |
| 59 SetImage(theImage); | |
| 60 } else { | |
| 61 SetImage(OmniboxViewMac::ImageForResource(image_id)); | 42 SetImage(OmniboxViewMac::ImageForResource(image_id)); |
| 43 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); |
| 44 return; |
| 62 } | 45 } |
| 46 SetImage(GetMaterialIcon(location_bar_is_dark)); |
| 63 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); | 47 tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]); |
| 64 } | 48 } |
| 65 | 49 |
| 66 NSPoint StarDecoration::GetBubblePointInFrame(NSRect frame) { | 50 NSPoint StarDecoration::GetBubblePointInFrame(NSRect frame) { |
| 67 const NSRect draw_frame = GetDrawRectInFrame(frame); | 51 const NSRect draw_frame = GetDrawRectInFrame(frame); |
| 68 return NSMakePoint(NSMidX(draw_frame), | 52 return NSMakePoint(NSMidX(draw_frame), |
| 69 NSMaxY(draw_frame) - kStarPointYOffset); | 53 NSMaxY(draw_frame) - kStarPointYOffset); |
| 70 } | 54 } |
| 71 | 55 |
| 72 bool StarDecoration::AcceptsMousePress() { | 56 bool StarDecoration::AcceptsMousePress() { |
| 73 return true; | 57 return true; |
| 74 } | 58 } |
| 75 | 59 |
| 76 bool StarDecoration::OnMousePressed(NSRect frame, NSPoint location) { | 60 bool StarDecoration::OnMousePressed(NSRect frame, NSPoint location) { |
| 77 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); | 61 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); |
| 78 return true; | 62 return true; |
| 79 } | 63 } |
| 80 | 64 |
| 81 NSString* StarDecoration::GetToolTip() { | 65 NSString* StarDecoration::GetToolTip() { |
| 82 return tooltip_.get(); | 66 return tooltip_.get(); |
| 83 } | 67 } |
| 68 |
| 69 SkColor StarDecoration::GetMaterialIconColor(bool location_bar_is_dark) { |
| 70 if (location_bar_is_dark) { |
| 71 return starred_ ? gfx::kGoogleBlue300 : SkColorSetA(SK_ColorWHITE, 0xCC); |
| 72 } |
| 73 return starred_ ? gfx::kGoogleBlue500 : gfx::kChromeIconGrey; |
| 74 } |
| 75 |
| 76 gfx::VectorIconId StarDecoration::GetMaterialVectorIconId() { |
| 77 return starred_ ? gfx::VectorIconId::LOCATION_BAR_STAR_ACTIVE |
| 78 : gfx::VectorIconId::LOCATION_BAR_STAR; |
| 79 } |
| OLD | NEW |