| 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..1a5e6e05b44d285c8c3d1062d4d72be572144c58 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
|
| @@ -7,14 +7,18 @@
|
| #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/autocomplete_text_field.h"
|
| +#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.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 +26,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 +41,58 @@ void ZoomDecoration::Update(ZoomController* zoom_controller) {
|
| tooltip_.reset([zoom_string retain]);
|
|
|
| SetVisible(true);
|
| +
|
| + [bubble_ onZoomChanged];
|
| +}
|
| +
|
| +void ZoomDecoration::ShowBubble(BOOL auto_close) {
|
| + content::WebContents* web_contents = owner_->GetWebContents();
|
| + if (!web_contents)
|
| + return;
|
| +
|
| + // Get the frame of the decoration.
|
| + AutocompleteTextField* field = owner_->GetAutocompleteTextField();
|
| + AutocompleteTextFieldCell* cell = [field cell];
|
| + const NSRect frame = [cell frameForDecoration:this
|
| + inFrame:[field bounds]];
|
| +
|
| + // Find point for bubble's arrow in screen coordinates.
|
| + 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:auto_close];
|
| +}
|
| +
|
| +NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
|
| + NSSize image_size = [GetImage() size];
|
| + frame.origin.x += frame.size.width - image_size.width;
|
| + 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) {
|
| + ShowBubble(NO);
|
| + return true;
|
| +}
|
| +
|
| NSString* ZoomDecoration::GetToolTip() {
|
| return tooltip_.get();
|
| }
|
|
|