OLD | NEW |
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 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 21 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
22 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
26 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
27 #import "third_party/mozilla/NSPasteboard+Utils.h" | 27 #import "third_party/mozilla/NSPasteboard+Utils.h" |
28 #include "ui/base/clipboard/clipboard.h" | 28 #include "ui/base/clipboard/clipboard.h" |
29 #import "ui/base/cocoa/cocoa_event_utils.h" | 29 #import "ui/base/cocoa/cocoa_event_utils.h" |
30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/font_list.h" |
| 32 #include "ui/gfx/geometry/rect.h" |
32 | 33 |
33 using content::WebContents; | 34 using content::WebContents; |
34 | 35 |
35 // Focus-handling between |field_| and model() is a bit subtle. | 36 // Focus-handling between |field_| and model() is a bit subtle. |
36 // Other platforms detect change of focus, which is inconvenient | 37 // Other platforms detect change of focus, which is inconvenient |
37 // without subclassing NSTextField (even with a subclass, the use of a | 38 // without subclassing NSTextField (even with a subclass, the use of a |
38 // field editor may complicate things). | 39 // field editor may complicate things). |
39 // | 40 // |
40 // model() doesn't actually do anything when it gains focus, it just | 41 // model() doesn't actually do anything when it gains focus, it just |
41 // initializes. Visible activity happens only after the user edits. | 42 // initializes. Visible activity happens only after the user edits. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // read. | 118 // read. |
118 NSRange ComponentToNSRange(const url_parse::Component& component) { | 119 NSRange ComponentToNSRange(const url_parse::Component& component) { |
119 return NSMakeRange(static_cast<NSInteger>(component.begin), | 120 return NSMakeRange(static_cast<NSInteger>(component.begin), |
120 static_cast<NSInteger>(component.len)); | 121 static_cast<NSInteger>(component.len)); |
121 } | 122 } |
122 | 123 |
123 } // namespace | 124 } // namespace |
124 | 125 |
125 // static | 126 // static |
126 NSImage* OmniboxViewMac::ImageForResource(int resource_id) { | 127 NSImage* OmniboxViewMac::ImageForResource(int resource_id) { |
127 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 128 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
128 return rb.GetNativeImageNamed(resource_id).ToNSImage(); | 129 return rb.GetNativeImageNamed(resource_id).ToNSImage(); |
129 } | 130 } |
130 | 131 |
131 // static | 132 // static |
132 NSColor* OmniboxViewMac::SuggestTextColor() { | 133 NSColor* OmniboxViewMac::SuggestTextColor() { |
133 return [NSColor colorWithCalibratedWhite:0.0 alpha:0.5]; | 134 return [NSColor colorWithCalibratedWhite:0.0 alpha:0.5]; |
134 } | 135 } |
135 | 136 |
136 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, | 137 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, |
137 Profile* profile, | 138 Profile* profile, |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 // call it if this behavior is desired. | 936 // call it if this behavior is desired. |
936 if (select_all || ![field_ currentEditor]) | 937 if (select_all || ![field_ currentEditor]) |
937 [[field_ window] makeFirstResponder:field_]; | 938 [[field_ window] makeFirstResponder:field_]; |
938 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); | 939 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); |
939 } | 940 } |
940 } | 941 } |
941 | 942 |
942 // static | 943 // static |
943 NSFont* OmniboxViewMac::GetFieldFont() { | 944 NSFont* OmniboxViewMac::GetFieldFont() { |
944 // This value should be kept in sync with InstantPage::InitializeFonts. | 945 // This value should be kept in sync with InstantPage::InitializeFonts. |
945 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 946 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
946 return rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1).GetNativeFont(); | 947 return rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1) |
| 948 .GetPrimaryFont().GetNativeFont(); |
947 } | 949 } |
948 | 950 |
949 int OmniboxViewMac::GetOmniboxTextLength() const { | 951 int OmniboxViewMac::GetOmniboxTextLength() const { |
950 return static_cast<int>(GetTextLength()); | 952 return static_cast<int>(GetTextLength()); |
951 } | 953 } |
952 | 954 |
953 NSUInteger OmniboxViewMac::GetTextLength() const { | 955 NSUInteger OmniboxViewMac::GetTextLength() const { |
954 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 956 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
955 [[field_ stringValue] length]; | 957 [[field_ stringValue] length]; |
956 } | 958 } |
957 | 959 |
958 bool OmniboxViewMac::IsCaretAtEnd() const { | 960 bool OmniboxViewMac::IsCaretAtEnd() const { |
959 const NSRange selection = GetSelectedRange(); | 961 const NSRange selection = GetSelectedRange(); |
960 return NSMaxRange(selection) == GetTextLength(); | 962 return NSMaxRange(selection) == GetTextLength(); |
961 } | 963 } |
OLD | NEW |