| 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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #import "content/browser/web_contents/web_contents_view_mac.h" | 7 #import "content/browser/web_contents/web_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 void WebContentsViewMac::SizeContents(const gfx::Size& size) { | 154 void WebContentsViewMac::SizeContents(const gfx::Size& size) { |
| 155 // TODO(brettw | japhet) This is a hack and should be removed. | 155 // TODO(brettw | japhet) This is a hack and should be removed. |
| 156 // See web_contents_view.h. | 156 // See web_contents_view.h. |
| 157 // Note(erikchen): This method has /never/ worked correctly. I've removed the | 157 // Note(erikchen): This method has /never/ worked correctly. I've removed the |
| 158 // previous implementation. | 158 // previous implementation. |
| 159 } | 159 } |
| 160 | 160 |
| 161 void WebContentsViewMac::Focus() { | 161 void WebContentsViewMac::Focus() { |
| 162 NSWindow* window = [cocoa_view_.get() window]; | 162 RenderWidgetHostView* rwhv = |
| 163 [window makeFirstResponder:GetContentNativeView()]; | 163 web_contents_->GetFullscreenRenderWidgetHostView(); |
| 164 if (!rwhv) |
| 165 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 166 const gfx::NativeView native_view = rwhv ? rwhv->GetNativeView() : nil; |
| 167 NSWindow* const window = [native_view window]; |
| 168 [window makeFirstResponder:native_view]; |
| 164 if (![window isVisible]) | 169 if (![window isVisible]) |
| 165 return; | 170 return; |
| 166 [window makeKeyAndOrderFront:nil]; | 171 [window makeKeyAndOrderFront:nil]; |
| 167 } | 172 } |
| 168 | 173 |
| 169 void WebContentsViewMac::SetInitialFocus() { | 174 void WebContentsViewMac::SetInitialFocus() { |
| 170 if (web_contents_->FocusLocationBarByDefault()) | 175 if (web_contents_->FocusLocationBarByDefault()) |
| 171 web_contents_->SetFocusToLocationBar(false); | 176 web_contents_->SetFocusToLocationBar(false); |
| 172 else | 177 else |
| 173 [[cocoa_view_.get() window] makeFirstResponder:GetContentNativeView()]; | 178 Focus(); |
| 174 } | 179 } |
| 175 | 180 |
| 176 void WebContentsViewMac::StoreFocus() { | 181 void WebContentsViewMac::StoreFocus() { |
| 182 RenderWidgetHostView* rwhv = |
| 183 web_contents_->GetFullscreenRenderWidgetHostView(); |
| 184 if (!rwhv) |
| 185 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 186 const gfx::NativeView native_view = rwhv ? rwhv->GetNativeView() : nil; |
| 177 // We're explicitly being asked to store focus, so don't worry if there's | 187 // We're explicitly being asked to store focus, so don't worry if there's |
| 178 // already a view saved. | 188 // already a view saved. |
| 179 focus_tracker_.reset( | 189 focus_tracker_.reset( |
| 180 [[FocusTracker alloc] initWithWindow:[cocoa_view_ window]]); | 190 [[FocusTracker alloc] initWithWindow:[native_view window]]); |
| 181 } | 191 } |
| 182 | 192 |
| 183 void WebContentsViewMac::RestoreFocus() { | 193 void WebContentsViewMac::RestoreFocus() { |
| 194 RenderWidgetHostView* rwhv = |
| 195 web_contents_->GetFullscreenRenderWidgetHostView(); |
| 196 if (!rwhv) |
| 197 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 198 const gfx::NativeView native_view = rwhv ? rwhv->GetNativeView() : nil; |
| 184 // TODO(avi): Could we be restoring a view that's no longer in the key view | 199 // TODO(avi): Could we be restoring a view that's no longer in the key view |
| 185 // chain? | 200 // chain? |
| 186 if (!(focus_tracker_.get() && | 201 if (!(focus_tracker_.get() && |
| 187 [focus_tracker_ restoreFocusInWindow:[cocoa_view_ window]])) { | 202 [focus_tracker_ restoreFocusInWindow:[native_view window]])) { |
| 188 // Fall back to the default focus behavior if we could not restore focus. | 203 // Fall back to the default focus behavior if we could not restore focus. |
| 189 // TODO(shess): If location-bar gets focus by default, this will | 204 // TODO(shess): If location-bar gets focus by default, this will |
| 190 // select-all in the field. If there was a specific selection in | 205 // select-all in the field. If there was a specific selection in |
| 191 // the field when we navigated away from it, we should restore | 206 // the field when we navigated away from it, we should restore |
| 192 // that selection. | 207 // that selection. |
| 193 SetInitialFocus(); | 208 SetInitialFocus(); |
| 194 } | 209 } |
| 195 | 210 |
| 196 focus_tracker_.reset(nil); | 211 focus_tracker_.reset(nil); |
| 197 } | 212 } |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // When the subviews require a layout, their size should be reset to the size | 592 // When the subviews require a layout, their size should be reset to the size |
| 578 // of this view. (It is possible for the size to get out of sync as an | 593 // of this view. (It is possible for the size to get out of sync as an |
| 579 // optimization in preparation for an upcoming WebContentsView resize. | 594 // optimization in preparation for an upcoming WebContentsView resize. |
| 580 // http://crbug.com/264207) | 595 // http://crbug.com/264207) |
| 581 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { | 596 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
| 582 for (NSView* subview in self.subviews) | 597 for (NSView* subview in self.subviews) |
| 583 [subview setFrame:self.bounds]; | 598 [subview setFrame:self.bounds]; |
| 584 } | 599 } |
| 585 | 600 |
| 586 @end | 601 @end |
| OLD | NEW |