OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 const AutocompleteEditModel::State model_state; | 97 const AutocompleteEditModel::State model_state; |
98 const bool has_focus; | 98 const bool has_focus; |
99 const NSRange selection; | 99 const NSRange selection; |
100 }; | 100 }; |
101 | 101 |
102 // Returns a lazily initialized property bag accessor for saving our | 102 // Returns a lazily initialized property bag accessor for saving our |
103 // state in a TabContents. When constructed |accessor| generates a | 103 // state in a TabContents. When constructed |accessor| generates a |
104 // globally-unique id used to index into the per-tab PropertyBag used | 104 // globally-unique id used to index into the per-tab PropertyBag used |
105 // to store the state data. | 105 // to store the state data. |
106 PropertyAccessor<OmniboxViewMacState>* GetStateAccessor() { | 106 base::PropertyAccessor<OmniboxViewMacState>* GetStateAccessor() { |
107 CR_DEFINE_STATIC_LOCAL(PropertyAccessor<OmniboxViewMacState>, accessor, ()); | 107 CR_DEFINE_STATIC_LOCAL( |
| 108 base::PropertyAccessor<OmniboxViewMacState>, accessor, ()); |
108 return &accessor; | 109 return &accessor; |
109 } | 110 } |
110 | 111 |
111 // Accessors for storing and getting the state from the tab. | 112 // Accessors for storing and getting the state from the tab. |
112 void StoreStateToTab(TabContents* tab, | 113 void StoreStateToTab(TabContents* tab, |
113 const OmniboxViewMacState& state) { | 114 const OmniboxViewMacState& state) { |
114 GetStateAccessor()->SetProperty(tab->property_bag(), state); | 115 GetStateAccessor()->SetProperty(tab->property_bag(), state); |
115 } | 116 } |
116 const OmniboxViewMacState* GetStateFromTab(const TabContents* tab) { | 117 const OmniboxViewMacState* GetStateFromTab(const TabContents* tab) { |
117 return GetStateAccessor()->GetProperty(tab->property_bag()); | 118 return GetStateAccessor()->GetProperty(tab->property_bag()); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 | 1122 |
1122 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1123 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
1123 DCHECK(pos <= GetTextLength()); | 1124 DCHECK(pos <= GetTextLength()); |
1124 SetSelectedRange(NSMakeRange(pos, pos)); | 1125 SetSelectedRange(NSMakeRange(pos, pos)); |
1125 } | 1126 } |
1126 | 1127 |
1127 bool OmniboxViewMac::IsCaretAtEnd() const { | 1128 bool OmniboxViewMac::IsCaretAtEnd() const { |
1128 const NSRange selection = GetSelectedRange(); | 1129 const NSRange selection = GetSelectedRange(); |
1129 return selection.length == 0 && selection.location == GetTextLength(); | 1130 return selection.length == 0 && selection.location == GetTextLength(); |
1130 } | 1131 } |
OLD | NEW |