Home | History | Annotate | Download | only in location_bar
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
      6 
      7 #include "chrome/app/chrome_command_ids.h"
      8 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
      9 #include "chrome/browser/command_updater.h"
     10 #include "grit/generated_resources.h"
     11 #include "grit/theme_resources.h"
     12 #include "ui/base/l10n/l10n_util_mac.h"
     13 
     14 namespace {
     15 
     16 // The info-bubble point should look like it points to the point
     17 // between the star's lower tips.  The popup should be where the
     18 // Omnibox popup ends up (2px below field).  Determined via Pixie.app
     19 // magnification.
     20 const CGFloat kStarPointYOffset = 2.0;
     21 
     22 }  // namespace
     23 
     24 StarDecoration::StarDecoration(CommandUpdater* command_updater)
     25     : command_updater_(command_updater) {
     26   SetVisible(true);
     27   SetStarred(false);
     28 }
     29 
     30 StarDecoration::~StarDecoration() {
     31 }
     32 
     33 void StarDecoration::SetStarred(bool starred) {
     34   const int image_id = starred ? IDR_STAR_LIT : IDR_STAR;
     35   const int tip_id = starred ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR;
     36   SetImage(AutocompleteEditViewMac::ImageForResource(image_id));
     37   tooltip_.reset([l10n_util::GetNSStringWithFixup(tip_id) retain]);
     38 }
     39 
     40 NSPoint StarDecoration::GetBubblePointInFrame(NSRect frame) {
     41   const NSRect draw_frame = GetDrawRectInFrame(frame);
     42   return NSMakePoint(NSMidX(draw_frame),
     43                      NSMaxY(draw_frame) - kStarPointYOffset);
     44 }
     45 
     46 bool StarDecoration::AcceptsMousePress() {
     47   return true;
     48 }
     49 
     50 bool StarDecoration::OnMousePressed(NSRect frame) {
     51   command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE);
     52   return true;
     53 }
     54 
     55 NSString* StarDecoration::GetToolTip() {
     56   return tooltip_.get();
     57 }
     58