Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8686)

Unified Diff: chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm

Issue 12286006: [Mac] Implement the basic zoom bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
}

Powered by Google App Engine
This is Rietveld 408576698