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

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

Issue 194110: Convert the AutocompletePopupPositioner into a BubblePositioner in preparatio... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/mac_util.h" 8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "base/gfx/rect.h" 10 #include "base/gfx/rect.h"
11 #include "chrome/app/chrome_dll_resource.h" 11 #include "chrome/app/chrome_dll_resource.h"
12 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 12 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
13 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" 13 #include "chrome/browser/bubble_positioner.h"
14 #import "chrome/browser/cocoa/autocomplete_text_field.h" 14 #import "chrome/browser/cocoa/autocomplete_text_field.h"
15 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 15 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
16 #import "chrome/browser/cocoa/back_forward_menu_controller.h" 16 #import "chrome/browser/cocoa/back_forward_menu_controller.h"
17 #import "chrome/browser/cocoa/gradient_button_cell.h" 17 #import "chrome/browser/cocoa/gradient_button_cell.h"
18 #import "chrome/browser/cocoa/location_bar_view_mac.h" 18 #import "chrome/browser/cocoa/location_bar_view_mac.h"
19 #import "chrome/browser/cocoa/menu_button.h" 19 #import "chrome/browser/cocoa/menu_button.h"
20 #include "chrome/browser/cocoa/nsimage_cache.h" 20 #include "chrome/browser/cocoa/nsimage_cache.h"
21 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
22 #include "chrome/browser/search_engines/template_url_model.h" 22 #include "chrome/browser/search_engines/template_url_model.h"
23 #include "chrome/browser/toolbar_model.h" 23 #include "chrome/browser/toolbar_model.h"
(...skipping 13 matching lines...) Expand all
37 // Overlap (in pixels) between the toolbar and the bookmark bar. 37 // Overlap (in pixels) between the toolbar and the bookmark bar.
38 static const float kBookmarkBarOverlap = 7.0; 38 static const float kBookmarkBarOverlap = 7.0;
39 39
40 @interface ToolbarController(Private) 40 @interface ToolbarController(Private)
41 - (void)initCommandStatus:(CommandUpdater*)commands; 41 - (void)initCommandStatus:(CommandUpdater*)commands;
42 - (void)prefChanged:(std::wstring*)prefName; 42 - (void)prefChanged:(std::wstring*)prefName;
43 @end 43 @end
44 44
45 namespace { 45 namespace {
46 46
47 // A C++ class used to correctly position the autocomplete popup. 47 // A C++ class used to correctly position the omnibox.
48 class AutocompletePopupPositionerMac : public AutocompletePopupPositioner { 48 class BubblePositionerMac : public BubblePositioner {
49 public: 49 public:
50 AutocompletePopupPositionerMac(ToolbarController* controller) 50 BubblePositionerMac(ToolbarController* controller)
51 : controller_(controller) { } 51 : controller_(controller) { }
52 virtual ~AutocompletePopupPositionerMac() { } 52 virtual ~BubblePositionerMac() { }
53 53
54 // Overridden from AutocompletePopupPositioner. 54 // BubblePositioner:
55 virtual gfx::Rect GetPopupBounds() const { 55 virtual gfx::Rect GetLocationStackBounds() const {
56 return [controller_ autocompletePopupPosition]; 56 return [controller_ locationStackBounds];
57 } 57 }
58 58
59 private: 59 private:
60 ToolbarController* controller_; // weak, owns us 60 ToolbarController* controller_; // weak, owns us
61 }; 61 };
62 62
63 } // namespace 63 } // namespace
64 64
65 namespace ToolbarControllerInternal { 65 namespace ToolbarControllerInternal {
66 66
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (trackingArea_.get()) 121 if (trackingArea_.get())
122 [[self view] removeTrackingArea:trackingArea_.get()]; 122 [[self view] removeTrackingArea:trackingArea_.get()];
123 [super dealloc]; 123 [super dealloc];
124 } 124 }
125 125
126 // Called after the view is done loading and the outlets have been hooked up. 126 // Called after the view is done loading and the outlets have been hooked up.
127 // Now we can hook up bridges that rely on UI objects such as the location 127 // Now we can hook up bridges that rely on UI objects such as the location
128 // bar and button state. 128 // bar and button state.
129 - (void)awakeFromNib { 129 - (void)awakeFromNib {
130 [self initCommandStatus:commands_]; 130 [self initCommandStatus:commands_];
131 popupPositioner_.reset(new AutocompletePopupPositionerMac(self)); 131 bubblePositioner_.reset(new BubblePositionerMac(self));
132 locationBarView_.reset(new LocationBarViewMac(locationBar_, 132 locationBarView_.reset(new LocationBarViewMac(locationBar_,
133 popupPositioner_.get(), 133 bubblePositioner_.get(),
134 commands_, toolbarModel_, 134 commands_, toolbarModel_,
135 profile_)); 135 profile_));
136 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 136 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
137 137
138 // Register pref observers for the optional home and page/options buttons 138 // Register pref observers for the optional home and page/options buttons
139 // and then add them to the toolbar them based on those prefs. 139 // and then add them to the toolbar them based on those prefs.
140 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self)); 140 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self));
141 PrefService* prefs = profile_->GetPrefs(); 141 PrefService* prefs = profile_->GetPrefs();
142 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get()); 142 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get());
143 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs, 143 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs,
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 template_url_model->GetDefaultSearchProvider() : 507 template_url_model->GetDefaultSearchProvider() :
508 template_url_model->GetTemplateURLForKeyword(keyword); 508 template_url_model->GetTemplateURLForKeyword(keyword);
509 if (!provider) 509 if (!provider)
510 return nil; 510 return nil;
511 std::wstring shortName(provider->AdjustedShortNameForLocaleDirection()); 511 std::wstring shortName(provider->AdjustedShortNameForLocaleDirection());
512 return l10n_util::GetNSStringF(IDS_TOOLTIP_GO_SEARCH, 512 return l10n_util::GetNSStringF(IDS_TOOLTIP_GO_SEARCH,
513 WideToUTF16(shortName), currentText16); 513 WideToUTF16(shortName), currentText16);
514 514
515 } 515 }
516 516
517 - (gfx::Rect)autocompletePopupPosition { 517 - (gfx::Rect)locationStackBounds {
518 // The popup should span from the left edge of the star button to the right 518 // The number of pixels from the left or right edges of the location stack to
519 // edge of the go button. The returned height is ignored. 519 // "just inside the visible borders". When the omnibox bubble contents are
520 // aligned with this, the visible borders tacked on to the outsides will line
521 // up with the visible borders on the location stack.
522 const int kLocationStackEdgeWidth = 2;
523
520 NSRect locationFrame = [locationBar_ frame]; 524 NSRect locationFrame = [locationBar_ frame];
521 // TODO(shess): The buttons have an extra 2 pixels between the edge 525 int minX = NSMinX([starButton_ frame]);
522 // of the visual button and the edge of the logical button. This 526 int maxX = NSMaxX([goButton_ frame]);
523 // seems wrong.
524 int minX = NSMinX([starButton_ frame]) + 2.0;
525 int maxX = NSMaxX([goButton_ frame]) - 2.0;
526 DCHECK(minX < NSMinX(locationFrame)); 527 DCHECK(minX < NSMinX(locationFrame));
527 DCHECK(maxX > NSMaxX(locationFrame)); 528 DCHECK(maxX > NSMaxX(locationFrame));
528 529
529 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, 0); 530 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX,
530 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil])); 531 NSHeight(locationFrame));
532 gfx::Rect stack_bounds(
533 NSRectToCGRect([[self view] convertRect:r toView:nil]));
534 // Inset the bounds to just inside the visible edges (see comment above).
535 stack_bounds.Inset(kLocationStackEdgeWidth, 0);
536 return stack_bounds;
531 } 537 }
532 @end 538 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698