| OLD | NEW |
| 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/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/views/browser_dialogs.h" | 10 #include "chrome/browser/views/browser_dialogs.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 static const int64 kDisallowClickMS = 40; | 28 static const int64 kDisallowClickMS = 40; |
| 29 | 29 |
| 30 ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener, | 30 ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener, |
| 31 ToolbarView* host) | 31 ToolbarView* host) |
| 32 : ToggleImageButton(listener), | 32 : ToggleImageButton(listener), |
| 33 host_(host), | 33 host_(host), |
| 34 ignore_click_(false) { | 34 ignore_click_(false) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) { | 37 void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) { |
| 38 gfx::Rect bounds(host_->GetLocationStackBounds()); |
| 38 gfx::Point star_location; | 39 gfx::Point star_location; |
| 39 views::View::ConvertPointToScreen(this, &star_location); | 40 views::View::ConvertPointToScreen(this, &star_location); |
| 40 // Shift the x location by 1 as visually the center of the star appears 1 | 41 // The visual center of the star is not centered within the bounds. The star |
| 41 // pixel to the right. By doing this bubble arrow points to the center | 42 // has a single central pixel; there are 13 pixels on the "inside" side of it |
| 42 // of the star. | 43 // (toward the location bar) and 16 on the "outside". This means we need to |
| 43 gfx::Rect star_bounds(star_location.x() + 1, star_location.y(), width(), | 44 // shift the bounds one pixel toward the location bar in order to place the |
| 44 height()); | 45 // star's outside edge at the horizontal center. However, even this isn't |
| 45 browser::ShowBookmarkBubbleView(host_->GetWindow(), star_bounds, this, | 46 // 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 |
| 48 // 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' |
| 50 // center-line, so that the arrow's center will line up. |
| 51 // |
| 52 // TODO: If the InfoBubble used mirroring transformations maybe this could |
| 53 // become symmetric (-1 : 1). |
| 54 bounds.set_x(star_location.x() + (UILayoutIsRightToLeft() ? -2 : 1)); |
| 55 bounds.set_width(width()); |
| 56 browser::ShowBookmarkBubbleView(host_->GetWindow(), bounds, this, |
| 46 host_->profile(), url, newly_bookmarked); | 57 host_->profile(), url, newly_bookmarked); |
| 47 } | 58 } |
| 48 | 59 |
| 49 bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) { | 60 bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) { |
| 50 ignore_click_ = ((TimeTicks::Now() - bubble_closed_time_).InMilliseconds() < | 61 ignore_click_ = ((TimeTicks::Now() - bubble_closed_time_).InMilliseconds() < |
| 51 kDisallowClickMS); | 62 kDisallowClickMS); |
| 52 return ToggleImageButton::OnMousePressed(e); | 63 return ToggleImageButton::OnMousePressed(e); |
| 53 } | 64 } |
| 54 | 65 |
| 55 void ToolbarStarToggle::OnMouseReleased(const views::MouseEvent& e, | 66 void ToolbarStarToggle::OnMouseReleased(const views::MouseEvent& e, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 | 89 |
| 79 void ToolbarStarToggle::InfoBubbleClosing(InfoBubble* info_bubble, | 90 void ToolbarStarToggle::InfoBubbleClosing(InfoBubble* info_bubble, |
| 80 bool closed_by_escape) { | 91 bool closed_by_escape) { |
| 81 SchedulePaint(); | 92 SchedulePaint(); |
| 82 bubble_closed_time_ = TimeTicks::Now(); | 93 bubble_closed_time_ = TimeTicks::Now(); |
| 83 } | 94 } |
| 84 | 95 |
| 85 bool ToolbarStarToggle::CloseOnEscape() { | 96 bool ToolbarStarToggle::CloseOnEscape() { |
| 86 return true; | 97 return true; |
| 87 } | 98 } |
| OLD | NEW |