summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/location_bar/star_decoration.mm
blob: 08ee25ee35afb7f7f4843156c3213ddfc3a6c4a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"

#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.h"
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/grit/generated_resources.h"
#include "grit/components_strings.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"

namespace {

// The info-bubble point should look like it points to the point
// between the star's lower tips.  The popup should be where the
// Omnibox popup ends up (2px below field).  Determined via Pixie.app
// magnification.
const CGFloat kStarPointYOffset = 2.0;

}  // namespace

StarDecoration::StarDecoration(CommandUpdater* command_updater)
    : command_updater_(command_updater) {
  SetVisible(true);
  SetStarred(false, false);
}

StarDecoration::~StarDecoration() {
}

void StarDecoration::SetStarred(bool starred, bool locationBarIsDark) {
  starred_ = starred;
  const int image_id = starred ? IDR_STAR_LIT : IDR_STAR;
  const int tip_id = starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR;
  if (ui::MaterialDesignController::IsModeMaterial()) {
    NSImage* theImage;
    gfx::VectorIconId iconId = starred_ ?
        gfx::VectorIconId::LOCATION_BAR_STAR_ACTIVE :
        gfx::VectorIconId::LOCATION_BAR_STAR;
    SkColor starColor = gfx::kPlaceholderColor;
    if (locationBarIsDark) {
      starColor = SK_ColorWHITE;
    } else if (starred_) {
      starColor = gfx::kGoogleBlue500;
    } else {
      starColor = gfx::kChromeIconGrey;
    }
    theImage = NSImageFromImageSkia(gfx::CreateVectorIcon(
        iconId, 16, starColor));
    SetImage(theImage);
  } else {
    SetImage(OmniboxViewMac::ImageForResource(image_id));
  }
  tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]);
}

NSPoint StarDecoration::GetBubblePointInFrame(NSRect frame) {
  const NSRect draw_frame = GetDrawRectInFrame(frame);
  return NSMakePoint(NSMidX(draw_frame),
                     NSMaxY(draw_frame) - kStarPointYOffset);
}

bool StarDecoration::AcceptsMousePress() {
  return true;
}

bool StarDecoration::OnMousePressed(NSRect frame, NSPoint location) {
  command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE);
  return true;
}

NSString* StarDecoration::GetToolTip() {
  return tooltip_.get();
}