| 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 |
| 11 #import "base/mac/scoped_sending_event.h" | 11 #import "base/mac/scoped_sending_event.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #import "base/message_loop/message_pump_mac.h" | 13 #import "base/message_loop/message_pump_mac.h" |
| 14 #include "content/browser/frame_host/popup_menu_helper_mac.h" | 14 #include "content/browser/frame_host/popup_menu_helper_mac.h" |
| 15 #include "content/browser/renderer_host/render_view_host_factory.h" | 15 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 17 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" | 18 #include "content/browser/web_contents/web_contents_impl.h" |
| 19 #import "content/browser/web_contents/web_drag_dest_mac.h" | 19 #import "content/browser/web_contents/web_drag_dest_mac.h" |
| 20 #import "content/browser/web_contents/web_drag_source_mac.h" | 20 #import "content/browser/web_contents/web_drag_source_mac.h" |
| 21 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "content/public/browser/web_contents_view_delegate.h" | 23 #import "content/public/browser/web_contents_view_delegate_mac.h" |
| 24 #include "skia/ext/skia_utils_mac.h" | 24 #include "skia/ext/skia_utils_mac.h" |
| 25 #import "third_party/mozilla/NSPasteboard+Utils.h" | 25 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 26 #include "ui/base/clipboard/custom_data_helper.h" | 26 #include "ui/base/clipboard/custom_data_helper.h" |
| 27 #import "ui/base/cocoa/focus_tracker.h" | 27 #import "ui/base/cocoa/focus_tracker.h" |
| 28 #include "ui/base/dragdrop/cocoa_dnd_util.h" | 28 #include "ui/base/dragdrop/cocoa_dnd_util.h" |
| 29 #include "ui/gfx/image/image_skia_util_mac.h" | 29 #include "ui/gfx/image/image_skia_util_mac.h" |
| 30 | 30 |
| 31 using blink::WebDragOperation; | 31 using blink::WebDragOperation; |
| 32 using blink::WebDragOperationsMask; | 32 using blink::WebDragOperationsMask; |
| 33 using content::DropData; | 33 using content::DropData; |
| (...skipping 118 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 if (delegate_ && delegate_->Focus()) |
| 163 return; |
| 164 |
| 162 NSWindow* window = [cocoa_view_.get() window]; | 165 NSWindow* window = [cocoa_view_.get() window]; |
| 163 [window makeFirstResponder:GetContentNativeView()]; | 166 [window makeFirstResponder:GetContentNativeView()]; |
| 164 if (![window isVisible]) | 167 if (![window isVisible]) |
| 165 return; | 168 return; |
| 166 [window makeKeyAndOrderFront:nil]; | 169 [window makeKeyAndOrderFront:nil]; |
| 167 } | 170 } |
| 168 | 171 |
| 169 void WebContentsViewMac::SetInitialFocus() { | 172 void WebContentsViewMac::SetInitialFocus() { |
| 170 if (web_contents_->FocusLocationBarByDefault()) | 173 if (web_contents_->FocusLocationBarByDefault()) |
| 171 web_contents_->SetFocusToLocationBar(false); | 174 web_contents_->SetFocusToLocationBar(false); |
| 172 else | 175 else |
| 173 [[cocoa_view_.get() window] makeFirstResponder:GetContentNativeView()]; | 176 [[cocoa_view_.get() window] makeFirstResponder:GetContentNativeView()]; |
| 174 } | 177 } |
| 175 | 178 |
| 176 void WebContentsViewMac::StoreFocus() { | 179 void WebContentsViewMac::StoreFocus() { |
| 177 // We're explicitly being asked to store focus, so don't worry if there's | 180 // We're explicitly being asked to store focus, so don't worry if there's |
| 178 // already a view saved. | 181 // already a view saved. |
| 182 focus_tracker_.reset(); |
| 183 if (delegate_ && delegate_->StoreFocus()) |
| 184 return; |
| 185 |
| 179 focus_tracker_.reset( | 186 focus_tracker_.reset( |
| 180 [[FocusTracker alloc] initWithWindow:[cocoa_view_ window]]); | 187 [[FocusTracker alloc] initWithWindow:[cocoa_view_ window]]); |
| 181 } | 188 } |
| 182 | 189 |
| 183 void WebContentsViewMac::RestoreFocus() { | 190 void WebContentsViewMac::RestoreFocus() { |
| 184 // TODO(avi): Could we be restoring a view that's no longer in the key view | 191 // TODO(avi): Could we be restoring a view that's no longer in the key view |
| 185 // chain? | 192 // chain? |
| 193 if (delegate_ && delegate_->RestoreFocus()) |
| 194 return; |
| 195 |
| 186 if (!(focus_tracker_.get() && | 196 if (!(focus_tracker_.get() && |
| 187 [focus_tracker_ restoreFocusInWindow:[cocoa_view_ window]])) { | 197 [focus_tracker_ restoreFocusInWindow:[cocoa_view_ window]])) { |
| 188 // Fall back to the default focus behavior if we could not restore focus. | 198 // 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 | 199 // TODO(shess): If location-bar gets focus by default, this will |
| 190 // select-all in the field. If there was a specific selection in | 200 // select-all in the field. If there was a specific selection in |
| 191 // the field when we navigated away from it, we should restore | 201 // the field when we navigated away from it, we should restore |
| 192 // that selection. | 202 // that selection. |
| 193 SetInitialFocus(); | 203 SetInitialFocus(); |
| 194 } | 204 } |
| 195 | 205 |
| 196 focus_tracker_.reset(nil); | 206 focus_tracker_.reset(nil); |
| 197 } | 207 } |
| 198 | 208 |
| 199 DropData* WebContentsViewMac::GetDropData() const { | 209 DropData* WebContentsViewMac::GetDropData() const { |
| 200 return [cocoa_view_ dropData]; | 210 return [cocoa_view_ dropData]; |
| 201 } | 211 } |
| 202 | 212 |
| 203 void WebContentsViewMac::UpdateDragCursor(WebDragOperation operation) { | 213 void WebContentsViewMac::UpdateDragCursor(WebDragOperation operation) { |
| 204 [cocoa_view_ setCurrentDragOperation: operation]; | 214 [cocoa_view_ setCurrentDragOperation: operation]; |
| 205 } | 215 } |
| 206 | 216 |
| 207 void WebContentsViewMac::GotFocus() { | 217 void WebContentsViewMac::GotFocus() { |
| 208 // This is only used in the views FocusManager stuff but it bleeds through | 218 // This is only used in the views FocusManager stuff but it bleeds through |
| 209 // all subclasses. http://crbug.com/21875 | 219 // all subclasses. http://crbug.com/21875 |
| 210 } | 220 } |
| 211 | 221 |
| 212 // This is called when the renderer asks us to take focus back (i.e., it has | 222 // This is called when the renderer asks us to take focus back (i.e., it has |
| 213 // iterated past the last focusable element on the page). | 223 // iterated past the last focusable element on the page). |
| 214 void WebContentsViewMac::TakeFocus(bool reverse) { | 224 void WebContentsViewMac::TakeFocus(bool reverse) { |
| 225 if (delegate_ && delegate_->TakeFocus(reverse)) |
| 226 return; |
| 227 |
| 215 if (reverse) { | 228 if (reverse) { |
| 216 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; | 229 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; |
| 217 } else { | 230 } else { |
| 218 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; | 231 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; |
| 219 } | 232 } |
| 220 } | 233 } |
| 221 | 234 |
| 222 void WebContentsViewMac::ShowContextMenu( | 235 void WebContentsViewMac::ShowContextMenu( |
| 223 RenderFrameHost* render_frame_host, | 236 RenderFrameHost* render_frame_host, |
| 224 const ContextMenuParams& params) { | 237 const ContextMenuParams& params) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // view twice), we check for the RVH Factory, which will be set when we're | 305 // view twice), we check for the RVH Factory, which will be set when we're |
| 293 // making special ones (which go along with the special views). | 306 // making special ones (which go along with the special views). |
| 294 DCHECK(RenderViewHostFactory::has_factory()); | 307 DCHECK(RenderViewHostFactory::has_factory()); |
| 295 return static_cast<RenderWidgetHostViewBase*>( | 308 return static_cast<RenderWidgetHostViewBase*>( |
| 296 render_widget_host->GetView()); | 309 render_widget_host->GetView()); |
| 297 } | 310 } |
| 298 | 311 |
| 299 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac( | 312 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac( |
| 300 render_widget_host); | 313 render_widget_host); |
| 301 if (delegate()) { | 314 if (delegate()) { |
| 315 WebContentsViewDelegateMac* delegate_mac = |
| 316 delegate()->AsWebContentsViewDelegateMac(); |
| 302 base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate> > | 317 base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate> > |
| 303 rw_delegate( | 318 rw_delegate(delegate_mac |
| 304 delegate()->CreateRenderWidgetHostViewDelegate(render_widget_host)); | 319 ? delegate_mac->CreateRenderWidgetHostViewDelegate( |
| 320 render_widget_host) |
| 321 : nil); |
| 305 | 322 |
| 306 view->SetDelegate(rw_delegate.get()); | 323 view->SetDelegate(rw_delegate.get()); |
| 307 } | 324 } |
| 308 view->SetAllowPauseForResizeOrRepaint(!allow_other_views_); | 325 view->SetAllowPauseForResizeOrRepaint(!allow_other_views_); |
| 309 | 326 |
| 310 // Fancy layout comes later; for now just make it our size and resize it | 327 // Fancy layout comes later; for now just make it our size and resize it |
| 311 // with us. In case there are other siblings of the content area, we want | 328 // with us. In case there are other siblings of the content area, we want |
| 312 // to make sure the content area is on the bottom so other things draw over | 329 // to make sure the content area is on the bottom so other things draw over |
| 313 // it. | 330 // it. |
| 314 NSView* view_view = view->GetNativeView(); | 331 NSView* view_view = view->GetNativeView(); |
| (...skipping 262 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 | 594 // 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 | 595 // 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. | 596 // optimization in preparation for an upcoming WebContentsView resize. |
| 580 // http://crbug.com/264207) | 597 // http://crbug.com/264207) |
| 581 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { | 598 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
| 582 for (NSView* subview in self.subviews) | 599 for (NSView* subview in self.subviews) |
| 583 [subview setFrame:self.bounds]; | 600 [subview setFrame:self.bounds]; |
| 584 } | 601 } |
| 585 | 602 |
| 586 @end | 603 @end |
| OLD | NEW |