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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 2847173004: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: Created 3 years, 7 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
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 #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/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 ~OmniboxViewMacState() override {} 115 ~OmniboxViewMacState() override {}
116 116
117 const OmniboxEditModel::State model_state; 117 const OmniboxEditModel::State model_state;
118 const bool has_focus; 118 const bool has_focus;
119 const NSRange selection; 119 const NSRange selection;
120 }; 120 };
121 121
122 // Accessors for storing and getting the state from the tab. 122 // Accessors for storing and getting the state from the tab.
123 void StoreStateToTab(WebContents* tab, 123 void StoreStateToTab(WebContents* tab,
124 OmniboxViewMacState* state) { 124 std::unique_ptr<OmniboxViewMacState> state) {
125 tab->SetUserData(kOmniboxViewMacStateKey, state); 125 tab->SetUserData(kOmniboxViewMacStateKey, std::move(state));
126 } 126 }
127 127
128 const OmniboxViewMacState* GetStateFromTab(const WebContents* tab) { 128 const OmniboxViewMacState* GetStateFromTab(const WebContents* tab) {
129 return static_cast<OmniboxViewMacState*>( 129 return static_cast<OmniboxViewMacState*>(
130 tab->GetUserData(&kOmniboxViewMacStateKey)); 130 tab->GetUserData(&kOmniboxViewMacStateKey));
131 } 131 }
132 132
133 } // namespace 133 } // namespace
134 134
135 // static 135 // static
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 NSRange range; 216 NSRange range;
217 if (hasFocus) { 217 if (hasFocus) {
218 range = GetSelectedRange(); 218 range = GetSelectedRange();
219 } else { 219 } else {
220 // If we are not focused, there is no selection. Manufacture 220 // If we are not focused, there is no selection. Manufacture
221 // something reasonable in case it starts to matter in the future. 221 // something reasonable in case it starts to matter in the future.
222 range = NSMakeRange(0, GetTextLength()); 222 range = NSMakeRange(0, GetTextLength());
223 } 223 }
224 224
225 OmniboxViewMacState* state = 225 StoreStateToTab(tab, base::MakeUnique<OmniboxViewMacState>(
226 new OmniboxViewMacState(model()->GetStateForTabSwitch(), hasFocus, range); 226 model()->GetStateForTabSwitch(), hasFocus, range));
227 StoreStateToTab(tab, state);
228 } 227 }
229 228
230 void OmniboxViewMac::OnTabChanged(const WebContents* web_contents) { 229 void OmniboxViewMac::OnTabChanged(const WebContents* web_contents) {
231 const OmniboxViewMacState* state = GetStateFromTab(web_contents); 230 const OmniboxViewMacState* state = GetStateFromTab(web_contents);
232 model()->RestoreState(state ? &state->model_state : NULL); 231 model()->RestoreState(state ? &state->model_state : NULL);
233 // Restore focus and selection if they were present when the tab 232 // Restore focus and selection if they were present when the tab
234 // was switched away. 233 // was switched away.
235 if (state && state->has_focus) { 234 if (state && state->has_focus) {
236 // TODO(shess): Unfortunately, there is no safe way to update 235 // TODO(shess): Unfortunately, there is no safe way to update
237 // this because TabStripController -selectTabWithContents:* is 236 // this because TabStripController -selectTabWithContents:* is
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 display_text); 1082 display_text);
1084 NSDictionary* notification_info = @{ 1083 NSDictionary* notification_info = @{
1085 NSAccessibilityAnnouncementKey : announcement, 1084 NSAccessibilityAnnouncementKey : announcement,
1086 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) 1085 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
1087 }; 1086 };
1088 NSAccessibilityPostNotificationWithUserInfo( 1087 NSAccessibilityPostNotificationWithUserInfo(
1089 [field_ window], 1088 [field_ window],
1090 NSAccessibilityAnnouncementRequestedNotification, 1089 NSAccessibilityAnnouncementRequestedNotification,
1091 notification_info); 1090 notification_info);
1092 } 1091 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698