Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: chrome/browser/views/toolbar_star_toggle.cc

Issue 543215: Added Star button to compact navigation mode.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/toolbar_star_toggle.h ('k') | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/toolbar_star_toggle.h" 5 #include "chrome/browser/views/toolbar_star_toggle.h"
6 6
7 #include "app/l10n_util.h"
7 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "chrome/app/chrome_dll_resource.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_theme_provider.h"
13 #include "chrome/browser/bubble_positioner.h"
14 #include "chrome/browser/profile.h"
10 #include "chrome/browser/views/browser_dialogs.h" 15 #include "chrome/browser/views/browser_dialogs.h"
11 #include "chrome/browser/views/toolbar_view.h" 16 #include "chrome/browser/view_ids.h"
12 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
14 20
15 using base::TimeTicks; 21 using base::TimeTicks;
16 22
17 // The amount of time (in milliseconds) between when the bubble closes and when 23 // The amount of time (in milliseconds) between when the bubble closes and when
18 // pressing on the button again does something. Yes, this is a hackish. I tried 24 // pressing on the button again does something. Yes, this is a hackish. I tried
19 // many different options, all to no avail: 25 // many different options, all to no avail:
20 // . Keying off mouse activation: this didn't work as there is no way to know 26 // . Keying off mouse activation: this didn't work as there is no way to know
21 // which window receives the activation. Additionally once the mouse 27 // which window receives the activation. Additionally once the mouse
22 // activation occurs we have no way to tie the next mouse event to the mouse 28 // activation occurs we have no way to tie the next mouse event to the mouse
23 // activation. 29 // activation.
24 // . Watching all events as we dispatch them in the MessageLoop. Mouse 30 // . Watching all events as we dispatch them in the MessageLoop. Mouse
25 // activation isn't an observable event though. 31 // activation isn't an observable event though.
26 // Ideally we could use mouse capture for this, but we can't use mouse capture 32 // Ideally we could use mouse capture for this, but we can't use mouse capture
27 // with the bubble because it has other native windows. 33 // with the bubble because it has other native windows.
28 static const int64 kDisallowClickMS = 40; 34 static const int64 kDisallowClickMS = 40;
29 35
30 ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener, 36 ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* button_listener)
31 ToolbarView* host) 37 : ToggleImageButton(button_listener),
32 : ToggleImageButton(listener), 38 profile_(NULL),
33 host_(host), 39 host_view_(NULL),
40 bubble_positioner_(NULL),
34 ignore_click_(false) { 41 ignore_click_(false) {
35 } 42 }
36 43
44 void ToolbarStarToggle::Init() {
45 ThemeProvider* tp = profile_->GetThemeProvider();
46
47 set_tag(IDC_BOOKMARK_PAGE);
48 SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR));
49 SetToggledTooltipText(l10n_util::GetString(IDS_TOOLTIP_STARRED));
50 SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR));
51 SetID(VIEW_ID_STAR_BUTTON);
52
53 // Load images.
54 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
55 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND);
56
57 SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR));
58 SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H));
59 SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_STAR_P));
60 SetImage(views::CustomButton::BS_DISABLED, tp->GetBitmapNamed(IDR_STAR_D));
61 SetToggledImage(views::CustomButton::BS_NORMAL,
62 tp->GetBitmapNamed(IDR_STARRED));
63 SetToggledImage(views::CustomButton::BS_HOT,
64 tp->GetBitmapNamed(IDR_STARRED_H));
65 SetToggledImage(views::CustomButton::BS_PUSHED,
66 tp->GetBitmapNamed(IDR_STARRED_P));
67 SetBackground(color, background, tp->GetBitmapNamed(IDR_STAR_MASK));
68 }
69
37 void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) { 70 void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
38 gfx::Rect bounds(host_->GetLocationStackBounds()); 71 gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds());
39 gfx::Point star_location; 72 gfx::Point star_location;
40 views::View::ConvertPointToScreen(this, &star_location); 73 views::View::ConvertPointToScreen(this, &star_location);
41 // The visual center of the star is not centered within the bounds. The star 74 // The visual center of the star is not centered within the bounds. The star
42 // has a single central pixel; there are 13 pixels on the "inside" side of it 75 // has a single central pixel; there are 13 pixels on the "inside" side of it
43 // (toward the location bar) and 16 on the "outside". This means we need to 76 // (toward the location bar) and 16 on the "outside". This means we need to
44 // shift the bounds one pixel toward the location bar in order to place the 77 // shift the bounds one pixel toward the location bar in order to place the
45 // star's outside edge at the horizontal center. However, even this isn't 78 // star's outside edge at the horizontal center. However, even this isn't
46 // good enough in RTL mode, because the InfoBubble's arrow's central pixel is 79 // good enough in RTL mode, because the InfoBubble's arrow's central pixel is
47 // drawn with its left edge on the target rect center-line in both LTR and RTL 80 // drawn with its left edge on the target rect center-line in both LTR and RTL
48 // modes. So in RTL mode, we need to shift the bounds one more pixel left, in 81 // modes. So in RTL mode, we need to shift the bounds one more pixel left, in
49 // order to place the star's central pixel on the right side of the bounds' 82 // order to place the star's central pixel on the right side of the bounds'
50 // center-line, so that the arrow's center will line up. 83 // center-line, so that the arrow's center will line up.
51 // 84 //
52 // TODO: If the InfoBubble used mirroring transformations maybe this could 85 // TODO(pkasting): If the InfoBubble used mirroring transformations maybe this
53 // become symmetric (-1 : 1). 86 // could become symmetric (-1 : 1).
54 bounds.set_x(star_location.x() + (UILayoutIsRightToLeft() ? -2 : 1)); 87 bounds.set_x(star_location.x() + (UILayoutIsRightToLeft() ? -2 : 1));
55 bounds.set_width(width()); 88 bounds.set_width(width());
56 browser::ShowBookmarkBubbleView(host_->GetWindow(), bounds, this, 89 browser::ShowBookmarkBubbleView(host_view_->GetWindow(), bounds, this,
57 host_->profile(), url, newly_bookmarked); 90 profile_, url, newly_bookmarked);
58 } 91 }
59 92
60 bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) { 93 bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) {
61 ignore_click_ = ((TimeTicks::Now() - bubble_closed_time_).InMilliseconds() < 94 ignore_click_ = ((TimeTicks::Now() - bubble_closed_time_).InMilliseconds() <
62 kDisallowClickMS); 95 kDisallowClickMS);
63 return ToggleImageButton::OnMousePressed(e); 96 return ToggleImageButton::OnMousePressed(e);
64 } 97 }
65 98
66 void ToolbarStarToggle::OnMouseReleased(const views::MouseEvent& e, 99 void ToolbarStarToggle::OnMouseReleased(const views::MouseEvent& e,
67 bool canceled) { 100 bool canceled) {
(...skipping 21 matching lines...) Expand all
89 122
90 void ToolbarStarToggle::InfoBubbleClosing(InfoBubble* info_bubble, 123 void ToolbarStarToggle::InfoBubbleClosing(InfoBubble* info_bubble,
91 bool closed_by_escape) { 124 bool closed_by_escape) {
92 SchedulePaint(); 125 SchedulePaint();
93 bubble_closed_time_ = TimeTicks::Now(); 126 bubble_closed_time_ = TimeTicks::Now();
94 } 127 }
95 128
96 bool ToolbarStarToggle::CloseOnEscape() { 129 bool ToolbarStarToggle::CloseOnEscape() {
97 return true; 130 return true;
98 } 131 }
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_star_toggle.h ('k') | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698