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

Side by Side Diff: chrome/browser/cocoa/toolbar_controller.mm

Issue 173439: [Mac] The autocomplete popup now gets its position from the toolbar controlle... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/toolbar_controller.h" 5 #import "chrome/browser/cocoa/toolbar_controller.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "base/gfx/rect.h"
9 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/autocomplete/autocomplete_popup_view.h"
10 #import "chrome/browser/cocoa/autocomplete_text_field.h" 12 #import "chrome/browser/cocoa/autocomplete_text_field.h"
11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 13 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
12 #import "chrome/browser/cocoa/back_forward_menu_controller.h" 14 #import "chrome/browser/cocoa/back_forward_menu_controller.h"
13 #import "chrome/browser/cocoa/gradient_button_cell.h" 15 #import "chrome/browser/cocoa/gradient_button_cell.h"
14 #import "chrome/browser/cocoa/location_bar_view_mac.h" 16 #import "chrome/browser/cocoa/location_bar_view_mac.h"
15 #include "chrome/browser/cocoa/nsimage_cache.h" 17 #include "chrome/browser/cocoa/nsimage_cache.h"
16 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
17 #include "chrome/browser/toolbar_model.h" 19 #include "chrome/browser/toolbar_model.h"
18 #include "chrome/common/notification_details.h" 20 #include "chrome/common/notification_details.h"
19 #include "chrome/common/notification_observer.h" 21 #include "chrome/common/notification_observer.h"
20 #include "chrome/common/notification_type.h" 22 #include "chrome/common/notification_type.h"
21 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
22 #include "chrome/common/pref_service.h" 24 #include "chrome/common/pref_service.h"
23 25
24 // Name of image in the bundle for the yellow of the star icon. 26 // Name of image in the bundle for the yellow of the star icon.
25 static NSString* const kStarredImageName = @"starred.pdf"; 27 static NSString* const kStarredImageName = @"starred.pdf";
26 28
27 // Height of the toolbar in pixels when the bookmark bar is closed. 29 // Height of the toolbar in pixels when the bookmark bar is closed.
28 static const float kBaseToolbarHeight = 39.0; 30 static const float kBaseToolbarHeight = 39.0;
29 31
30 // Overlap (in pixels) between the toolbar and the bookmark bar. 32 // Overlap (in pixels) between the toolbar and the bookmark bar.
31 static const float kBookmarkBarOverlap = 5.0; 33 static const float kBookmarkBarOverlap = 5.0;
32 34
33 @interface ToolbarController(Private) 35 @interface ToolbarController(Private)
34 - (void)initCommandStatus:(CommandUpdater*)commands; 36 - (void)initCommandStatus:(CommandUpdater*)commands;
35 - (void)prefChanged:(std::wstring*)prefName; 37 - (void)prefChanged:(std::wstring*)prefName;
36 @end 38 @end
37 39
40 namespace {
41
42 // A C++ class used to correctly position the autocomplete popup.
43 class AutocompletePopupPositionerMac : public AutocompletePopupPositioner {
44 public:
45 AutocompletePopupPositionerMac(ToolbarController* controller)
46 : controller_(controller) { }
47 virtual ~AutocompletePopupPositionerMac() { }
48
49 // Overridden from AutocompletePopupPositioner.
50 virtual gfx::Rect GetPopupBounds() const {
51 return [controller_ autocompletePopupPosition];
52 }
53
54 private:
55 ToolbarController* controller_; // weak, owns us
56 };
57
58 } // namespace
59
38 namespace ToolbarControllerInternal { 60 namespace ToolbarControllerInternal {
39 61
40 // A C++ class registered for changes in preferences. Bridges the 62 // A C++ class registered for changes in preferences. Bridges the
41 // notification back to the ToolbarController. 63 // notification back to the ToolbarController.
42 class PrefObserverBridge : public NotificationObserver { 64 class PrefObserverBridge : public NotificationObserver {
43 public: 65 public:
44 PrefObserverBridge(ToolbarController* controller) 66 PrefObserverBridge(ToolbarController* controller)
45 : controller_(controller) { } 67 : controller_(controller) { }
46 // Overridden from NotificationObserver: 68 // Overridden from NotificationObserver:
47 virtual void Observe(NotificationType type, 69 virtual void Observe(NotificationType type,
48 const NotificationSource& source, 70 const NotificationSource& source,
49 const NotificationDetails& details) { 71 const NotificationDetails& details) {
50 if (type == NotificationType::PREF_CHANGED) 72 if (type == NotificationType::PREF_CHANGED)
51 [controller_ prefChanged:Details<std::wstring>(details).ptr()]; 73 [controller_ prefChanged:Details<std::wstring>(details).ptr()];
52 } 74 }
53 private: 75 private:
54 ToolbarController* controller_; // weak, owns us 76 ToolbarController* controller_; // weak, owns us
55 }; 77 };
56 78
57 } // namespace 79 } // namespace ToolbarControllerInternal
58 80
59 @implementation ToolbarController 81 @implementation ToolbarController
60 82
61 - (id)initWithModel:(ToolbarModel*)model 83 - (id)initWithModel:(ToolbarModel*)model
62 commands:(CommandUpdater*)commands 84 commands:(CommandUpdater*)commands
63 profile:(Profile*)profile 85 profile:(Profile*)profile
64 browser:(Browser*)browser 86 browser:(Browser*)browser
65 resizeDelegate:(id<ViewResizer>)resizeDelegate 87 resizeDelegate:(id<ViewResizer>)resizeDelegate
66 bookmarkDelegate:(id<BookmarkURLOpener>)delegate { 88 bookmarkDelegate:(id<BookmarkURLOpener>)delegate {
67 DCHECK(model && commands && profile); 89 DCHECK(model && commands && profile);
(...skipping 24 matching lines...) Expand all
92 hasToolbar_ = YES; 114 hasToolbar_ = YES;
93 115
94 [super dealloc]; 116 [super dealloc];
95 } 117 }
96 118
97 // Called after the view is done loading and the outlets have been hooked up. 119 // Called after the view is done loading and the outlets have been hooked up.
98 // Now we can hook up bridges that rely on UI objects such as the location 120 // Now we can hook up bridges that rely on UI objects such as the location
99 // bar and button state. 121 // bar and button state.
100 - (void)awakeFromNib { 122 - (void)awakeFromNib {
101 [self initCommandStatus:commands_]; 123 [self initCommandStatus:commands_];
102 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, 124 popupPositioner_.reset(new AutocompletePopupPositionerMac(self));
103 toolbarModel_, profile_)); 125 locationBarView_.reset(new LocationBarViewMac(locationBar_,
126 popupPositioner_.get(),
127 commands_, toolbarModel_,
128 profile_));
104 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 129 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
105 130
106 // Register pref observers for the optional home and page/options buttons 131 // Register pref observers for the optional home and page/options buttons
107 // and then add them to the toolbar them based on those prefs. 132 // and then add them to the toolbar them based on those prefs.
108 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self)); 133 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self));
109 PrefService* prefs = profile_->GetPrefs(); 134 PrefService* prefs = profile_->GetPrefs();
110 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get()); 135 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get());
111 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs, 136 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs,
112 prefObserver_.get()); 137 prefObserver_.get());
113 [self showOptionalHomeButton]; 138 [self showOptionalHomeButton];
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 [NSMenu popUpContextMenu:wrenchMenu_ 396 [NSMenu popUpContextMenu:wrenchMenu_
372 withEvent:[NSApp currentEvent] 397 withEvent:[NSApp currentEvent]
373 forView:wrenchButton_]; 398 forView:wrenchButton_];
374 } 399 }
375 400
376 - (NSRect)starButtonInWindowCoordinates { 401 - (NSRect)starButtonInWindowCoordinates {
377 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds] 402 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds]
378 fromView:starButton_]; 403 fromView:starButton_];
379 } 404 }
380 405
406 - (gfx::Rect)autocompletePopupPosition {
407 // The popup should span from the left edge of the star button to the right
408 // edge of the go button. The returned height is ignored.
409 NSRect locationFrame = [locationBar_ frame];
410 int minX = NSMinX([starButton_ frame]);
411 int maxX = NSMaxX([goButton_ frame]);
412 DCHECK(minX < NSMinX(locationFrame));
413 DCHECK(maxX > NSMaxX(locationFrame));
381 414
415 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, 0);
416 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil]));
417 }
382 @end 418 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/toolbar_controller.h ('k') | chrome/browser/cocoa/toolbar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698