Chromium Code Reviews| Index: chrome/browser/ui/views/location_bar/zoom_view.cc |
| diff --git a/chrome/browser/ui/views/location_bar/zoom_view.cc b/chrome/browser/ui/views/location_bar/zoom_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3804d5ae8e7c52f09559a263506f03746a03638d |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/location_bar/zoom_view.cc |
| @@ -0,0 +1,105 @@ |
| +// 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. |
| + |
| +#include "chrome/browser/ui/views/location_bar/zoom_view.h" |
| + |
| +#include "chrome/browser/ui/views/browser_dialogs.h" |
| +#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| +#include "chrome/browser/ui/view_ids.h" |
| +#include "grit/generated_resources.h" |
| +#include "grit/theme_resources_standard.h" |
| +#include "ui/base/accessibility/accessible_view_state.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| + |
| +ZoomView::ZoomView() |
| + // Initially set the icon state to the plus icon even if it should be |
| + // something else so that the location bar's layout can account for the |
| + // width needed to display it. |
|
Peter Kasting
2012/06/22 20:16:20
? I don't understand why this is important.
Would
Kyle Horimoto
2012/06/26 21:55:53
I set it to NONE, and directly called SetImageSize
|
| + : zoom_icon_state_(ZoomController::ZOOM_PLUS_ICON), |
| + zoom_percent_(100) { |
| + set_id(VIEW_ID_ZOOM_BUTTON); |
| + set_accessibility_focusable(true); |
| + |
| + Update(); |
| +} |
| + |
| +ZoomView::~ZoomView() { |
| +} |
| + |
| +void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { |
| + if (zoom_icon_state == zoom_icon_state_) |
| + return; |
| + |
| + zoom_icon_state_ = zoom_icon_state; |
| + Update(); |
| +} |
| + |
| +void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) { |
| + if (zoom_percent == zoom_percent_) |
| + return; |
| + |
| + zoom_percent_ = zoom_percent; |
| + Update(); |
| +} |
| + |
| +void ZoomView::Update() { |
| + switch (zoom_icon_state_) { |
| + case ZoomController::NONE: |
| + SetVisible(false); |
|
Peter Kasting
2012/06/22 20:16:20
I don't like that both the location bar and this c
Kyle Horimoto
2012/06/26 21:55:53
Done. Good idea - this is far more elegant.
|
| + ZoomBubbleView::CloseBubble(); |
| + break; |
| + |
| + case ZoomController::ZOOM_PLUS_ICON: |
| + SetVisible(true); |
| + SetTooltipText( |
| + l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); |
| + SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| + IDR_ZOOM_PLUS)); |
| + break; |
| + |
| + case ZoomController::ZOOM_MINUS_ICON: |
| + SetVisible(true); |
| + SetTooltipText( |
| + l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); |
| + SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| + IDR_ZOOM_MINUS)); |
| + break; |
| + |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { |
| + state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); |
| + state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| +} |
| + |
| +bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { |
| + // Don't show tooltip if the zoom bubble is displayed. |
| + if (ZoomBubbleView::IsShowing()) |
| + return false; |
| + |
| + return ImageView::GetTooltipText(p, tooltip); |
| +} |
| + |
| +bool ZoomView::OnMousePressed(const views::MouseEvent& event) { |
| + // Do nothing until mouse is released. |
| + return true; |
| +} |
| + |
| +void ZoomView::OnMouseReleased(const views::MouseEvent& event) { |
| + if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) |
| + ZoomBubbleView::ShowBubble(this, zoom_percent_, false); |
| +} |
| + |
| +bool ZoomView::OnKeyPressed(const views::KeyEvent& event) { |
| + if (event.key_code() == ui::VKEY_SPACE || |
|
Peter Kasting
2012/06/22 20:16:20
Nit: If you reverse this conditional you can avoid
Kyle Horimoto
2012/06/26 21:55:53
Done.
|
| + event.key_code() == ui::VKEY_RETURN) { |
| + ZoomBubbleView::ShowBubble(this, zoom_percent_, false); |
| + return true; |
| + } |
| + return false; |
| +} |