Chromium Code Reviews| Index: chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| index f0b3539e0abf592abdeb919802e353b7e2e8a45d..2437ee6515bd47e3a1e5897384b703ec64f42638 100644 |
| --- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| +++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| @@ -7,14 +7,16 @@ |
| #include "base/string16.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| +#import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" |
| +#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| -#include "chrome/browser/ui/toolbar/toolbar_model.h" |
| #include "chrome/browser/ui/zoom/zoom_controller.h" |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| -ZoomDecoration::ZoomDecoration(ToolbarModel* toolbar_model) |
| - : toolbar_model_(toolbar_model) { |
| +ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| + : owner_(owner), |
| + bubble_(nil) { |
| Update(NULL); |
| } |
| @@ -22,9 +24,8 @@ ZoomDecoration::~ZoomDecoration() { |
| } |
| void ZoomDecoration::Update(ZoomController* zoom_controller) { |
| - if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || |
| - toolbar_model_->GetInputInProgress()) { |
| - // TODO(dbeam): hide zoom bubble when it exists. |
| + if (!zoom_controller || zoom_controller->IsAtDefaultZoom()) { |
| + [bubble_ close]; |
| SetVisible(false); |
| return; |
| } |
| @@ -38,12 +39,50 @@ void ZoomDecoration::Update(ZoomController* zoom_controller) { |
| tooltip_.reset([zoom_string retain]); |
| SetVisible(true); |
| + |
| + [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.
|
| +} |
| + |
| +NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
| + NSSize image_size = [GetImage() size]; |
| + 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
|
| + frame.size = image_size; |
| + |
| + const NSRect draw_frame = GetDrawRectInFrame(frame); |
| + return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame)); |
| } |
| bool ZoomDecoration::AcceptsMousePress() { |
| return true; |
| } |
| +bool ZoomDecoration::OnMousePressed(NSRect frame) { |
| + content::WebContents* web_contents = owner_->GetWebContents(); |
| + if (!web_contents) |
| + return true; |
| + |
| + // Find point for bubble's arrow in screen coordinates. |
| + AutocompleteTextField* field = owner_->GetAutocompleteTextField(); |
| + NSPoint anchor = GetBubblePointInFrame(frame); |
| + anchor = [field convertPoint:anchor toView:nil]; |
| + anchor = [[field window] convertBaseToScreen:anchor]; |
| + |
| + if (!bubble_) { |
| + void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) { |
| + bubble_ = nil; |
| + }; |
| + bubble_ = |
| + [[ZoomBubbleController alloc] initWithParentWindow:[field window] |
| + closeObserver:observer]; |
| + } |
| + |
| + [bubble_ showForWebContents:web_contents |
| + anchoredAt:anchor |
| + autoClose:NO]; |
| + |
| + return true; |
| +} |
| + |
| NSString* ZoomDecoration::GetToolTip() { |
| return tooltip_.get(); |
| } |