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

Side by Side 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: Auto-close bubble 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/zoom_decoration.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/autocomplete_text_field.h"
12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 14 #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" 15 #include "chrome/browser/ui/zoom/zoom_controller.h"
13 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
15 18
16 ZoomDecoration::ZoomDecoration(ToolbarModel* toolbar_model) 19 ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
17 : toolbar_model_(toolbar_model) { 20 : owner_(owner),
21 bubble_(nil) {
18 Update(NULL); 22 Update(NULL);
19 } 23 }
20 24
21 ZoomDecoration::~ZoomDecoration() { 25 ZoomDecoration::~ZoomDecoration() {
22 } 26 }
23 27
24 void ZoomDecoration::Update(ZoomController* zoom_controller) { 28 void ZoomDecoration::Update(ZoomController* zoom_controller) {
25 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || 29 if (!zoom_controller || zoom_controller->IsAtDefaultZoom()) {
26 toolbar_model_->GetInputInProgress()) { 30 [bubble_ close];
27 // TODO(dbeam): hide zoom bubble when it exists.
28 SetVisible(false); 31 SetVisible(false);
29 return; 32 return;
30 } 33 }
31 34
32 SetImage(OmniboxViewMac::ImageForResource( 35 SetImage(OmniboxViewMac::ImageForResource(
33 zoom_controller->GetResourceForZoomLevel())); 36 zoom_controller->GetResourceForZoomLevel()));
34 37
35 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent()); 38 string16 zoom_percent = base::IntToString16(zoom_controller->zoom_percent());
36 NSString* zoom_string = 39 NSString* zoom_string =
37 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent); 40 l10n_util::GetNSStringFWithFixup(IDS_TOOLTIP_ZOOM, zoom_percent);
38 tooltip_.reset([zoom_string retain]); 41 tooltip_.reset([zoom_string retain]);
39 42
40 SetVisible(true); 43 SetVisible(true);
44
45 [bubble_ onZoomChanged];
46 }
47
48 void ZoomDecoration::ShowBubble(BOOL auto_close) {
49 content::WebContents* web_contents = owner_->GetWebContents();
50 if (!web_contents)
51 return;
52
53 // Get the frame of the decoration.
54 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
55 AutocompleteTextFieldCell* cell = [field cell];
56 const NSRect frame = [cell frameForDecoration:this
57 inFrame:[field bounds]];
58
59 // Find point for bubble's arrow in screen coordinates.
60 NSPoint anchor = GetBubblePointInFrame(frame);
61 anchor = [field convertPoint:anchor toView:nil];
62 anchor = [[field window] convertBaseToScreen:anchor];
63
64 if (!bubble_) {
65 void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) {
66 bubble_ = nil;
67 };
68 bubble_ =
69 [[ZoomBubbleController alloc] initWithParentWindow:[field window]
70 closeObserver:observer];
71 }
72
73 [bubble_ showForWebContents:web_contents
74 anchoredAt:anchor
75 autoClose:auto_close];
76 }
77
78 NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
79 NSSize image_size = [GetImage() size];
80 frame.origin.x += frame.size.width - image_size.width;
81 frame.size = image_size;
82
83 const NSRect draw_frame = GetDrawRectInFrame(frame);
84 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame));
41 } 85 }
42 86
43 bool ZoomDecoration::AcceptsMousePress() { 87 bool ZoomDecoration::AcceptsMousePress() {
44 return true; 88 return true;
45 } 89 }
46 90
91 bool ZoomDecoration::OnMousePressed(NSRect frame) {
92 ShowBubble(NO);
93 return true;
94 }
95
47 NSString* ZoomDecoration::GetToolTip() { 96 NSString* ZoomDecoration::GetToolTip() {
48 return tooltip_.get(); 97 return tooltip_.get();
49 } 98 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/zoom_decoration.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698