Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 6 | 6 |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" | |
| 11 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | |
| 10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 12 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_model.h" | |
| 12 #include "chrome/browser/ui/zoom/zoom_controller.h" | 13 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
| 15 | 16 |
| 16 ZoomDecoration::ZoomDecoration(ToolbarModel* toolbar_model) | 17 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| 17 : toolbar_model_(toolbar_model) { | 18 : owner_(owner), |
| 19 bubble_(nil) { | |
| 18 Update(NULL); | 20 Update(NULL); |
| 19 } | 21 } |
| 20 | 22 |
| 21 ZoomDecoration::~ZoomDecoration() { | 23 ZoomDecoration::~ZoomDecoration() { |
| 22 } | 24 } |
| 23 | 25 |
| 24 void ZoomDecoration::Update(ZoomController* zoom_controller) { | 26 void ZoomDecoration::Update(ZoomController* zoom_controller) { |
| 25 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || | 27 if (!zoom_controller || zoom_controller->IsAtDefaultZoom()) { |
| 26 toolbar_model_->GetInputInProgress()) { | 28 [bubble_ close]; |
| 27 // TODO(dbeam): hide zoom bubble when it exists. | |
| 28 SetVisible(false); | 29 SetVisible(false); |
| 29 return; | 30 return; |
| 30 } | 31 } |
| 31 | 32 |
| 32 SetImage(OmniboxViewMac::ImageForResource( | 33 SetImage(OmniboxViewMac::ImageForResource( |
| 33 zoom_controller->GetResourceForZoomLevel())); | 34 zoom_controller->GetResourceForZoomLevel())); |
| 34 | 35 |
| 35 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent()); | 36 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent()); |
| 36 NSString* zoom_string = | 37 NSString* zoom_string = |
| 37 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); | 38 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); |
| 38 tooltip_.reset([zoom_string retain]); | 39 tooltip_.reset([zoom_string retain]); |
| 39 | 40 |
| 40 SetVisible(true); | 41 SetVisible(true); |
| 42 | |
| 43 [bubble_ onZoomChanged]; | |
|
sail
2013/02/15 21:05:12
Do you need to allocate ZoomBubbleController here?
Robert Sesek
2013/02/15 21:39:20
Nope. Not yet, c.f. CL description.
| |
| 44 } | |
| 45 | |
| 46 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { | |
| 47 NSSize image_size = [GetImage() size]; | |
| 48 frame.origin.x += frame.size.width - image_size.width; | |
|
sail
2013/02/15 21:05:12
This code would be easier to understand if it didn
Robert Sesek
2013/02/15 21:39:20
This code is literally copied and pasted from anot
| |
| 49 frame.size = image_size; | |
| 50 | |
| 51 const NSRect draw_frame = GetDrawRectInFrame(frame); | |
| 52 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame)); | |
| 41 } | 53 } |
| 42 | 54 |
| 43 bool ZoomDecoration::AcceptsMousePress() { | 55 bool ZoomDecoration::AcceptsMousePress() { |
| 44 return true; | 56 return true; |
| 45 } | 57 } |
| 46 | 58 |
| 59 bool ZoomDecoration::OnMousePressed(NSRect frame) { | |
| 60 content::WebContents* web_contents = owner_->GetWebContents(); | |
| 61 if (!web_contents) | |
| 62 return true; | |
| 63 | |
| 64 // Find point for bubble's arrow in screen coordinates. | |
| 65 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); | |
| 66 NSPoint anchor = GetBubblePointInFrame(frame); | |
| 67 anchor = [field convertPoint:anchor toView:nil]; | |
| 68 anchor = [[field window] convertBaseToScreen:anchor]; | |
| 69 | |
| 70 if (!bubble_) { | |
| 71 void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) { | |
| 72 bubble_ = nil; | |
| 73 }; | |
| 74 bubble_ = | |
| 75 [[ZoomBubbleController alloc] initWithParentWindow:[field window] | |
| 76 closeObserver:observer]; | |
| 77 } | |
| 78 | |
| 79 [bubble_ showForWebContents:web_contents | |
| 80 anchoredAt:anchor | |
| 81 autoClose:NO]; | |
| 82 | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 47 NSString* ZoomDecoration::GetToolTip() { | 86 NSString* ZoomDecoration::GetToolTip() { |
| 48 return tooltip_.get(); | 87 return tooltip_.get(); |
| 49 } | 88 } |
| OLD | NEW |