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/extensions/extension_view_mac.h" |
| 6 |
5 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
6 | 8 |
7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 9 #include "base/mac/foundation_util.h" |
8 | 10 #include "chrome/browser/extensions/extension_view_host.h" |
| 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
9 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
10 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
11 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
12 #include "extensions/browser/extension_host.h" | 15 #include "extensions/browser/extension_host.h" |
13 #include "extensions/common/view_type.h" | 16 #include "extensions/common/view_type.h" |
14 | 17 |
15 // The minimum/maximum dimensions of the popup. | 18 // The minimum/maximum dimensions of the popup. |
16 const CGFloat ExtensionViewMac::kMinWidth = 25.0; | 19 const CGFloat ExtensionViewMac::kMinWidth = 25.0; |
17 const CGFloat ExtensionViewMac::kMinHeight = 25.0; | 20 const CGFloat ExtensionViewMac::kMinHeight = 25.0; |
18 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; | 21 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; |
19 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; | 22 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; |
20 | 23 |
21 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host, | 24 ExtensionViewMac::ExtensionViewMac(extensions::ExtensionHost* extension_host, |
22 Browser* browser) | 25 Browser* browser) |
23 : browser_(browser), | 26 : browser_(browser), |
24 extension_host_(extension_host), | 27 extension_host_(extension_host), |
25 container_(NULL) { | 28 container_(NULL) { |
26 DCHECK(extension_host_); | 29 DCHECK(extension_host_); |
27 [native_view() setHidden:YES]; | 30 [GetNativeView() setHidden:YES]; |
28 } | 31 } |
29 | 32 |
30 ExtensionViewMac::~ExtensionViewMac() { | 33 ExtensionViewMac::~ExtensionViewMac() { |
31 } | 34 } |
32 | 35 |
| 36 void ExtensionViewMac::WindowFrameChanged() { |
| 37 if (render_view_host()->GetView()) |
| 38 render_view_host()->GetView()->WindowFrameChanged(); |
| 39 } |
| 40 |
33 void ExtensionViewMac::Init() { | 41 void ExtensionViewMac::Init() { |
34 CreateWidgetHostView(); | 42 CreateWidgetHostView(); |
35 } | 43 } |
36 | 44 |
37 gfx::NativeView ExtensionViewMac::native_view() { | 45 Browser* ExtensionViewMac::GetBrowser() { |
| 46 return browser_; |
| 47 } |
| 48 |
| 49 gfx::NativeView ExtensionViewMac::GetNativeView() { |
38 return extension_host_->host_contents()->GetNativeView(); | 50 return extension_host_->host_contents()->GetNativeView(); |
39 } | 51 } |
40 | 52 |
41 content::RenderViewHost* ExtensionViewMac::render_view_host() const { | |
42 return extension_host_->render_view_host(); | |
43 } | |
44 | |
45 void ExtensionViewMac::DidStopLoading() { | |
46 ShowIfCompletelyLoaded(); | |
47 } | |
48 | |
49 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { | 53 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { |
50 if (container_) | 54 if (container_) |
51 container_->OnExtensionSizeChanged(this, new_size); | 55 container_->OnExtensionSizeChanged(this, new_size); |
52 } | 56 } |
53 | 57 |
54 void ExtensionViewMac::RenderViewCreated() { | 58 void ExtensionViewMac::RenderViewCreated() { |
55 extensions::ViewType host_type = extension_host_->extension_host_type(); | 59 extensions::ViewType host_type = extension_host_->extension_host_type(); |
56 if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { | 60 if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { |
57 gfx::Size min_size(ExtensionViewMac::kMinWidth, | 61 gfx::Size min_size(ExtensionViewMac::kMinWidth, |
58 ExtensionViewMac::kMinHeight); | 62 ExtensionViewMac::kMinHeight); |
59 gfx::Size max_size(ExtensionViewMac::kMaxWidth, | 63 gfx::Size max_size(ExtensionViewMac::kMaxWidth, |
60 ExtensionViewMac::kMaxHeight); | 64 ExtensionViewMac::kMaxHeight); |
61 render_view_host()->EnableAutoResize(min_size, max_size); | 65 render_view_host()->EnableAutoResize(min_size, max_size); |
62 } | 66 } |
63 } | 67 } |
64 | 68 |
65 void ExtensionViewMac::WindowFrameChanged() { | 69 void ExtensionViewMac::HandleKeyboardEvent( |
66 if (render_view_host()->GetView()) | 70 content::WebContents* source, |
67 render_view_host()->GetView()->WindowFrameChanged(); | 71 const content::NativeWebKeyboardEvent& event) { |
| 72 if (event.skip_in_browser || |
| 73 event.type == content::NativeWebKeyboardEvent::Char || |
| 74 extension_host_->extension_host_type() != |
| 75 extensions::VIEW_TYPE_EXTENSION_POPUP) |
| 76 return; |
| 77 |
| 78 ChromeEventProcessingWindow* event_window = |
| 79 base::mac::ObjCCastStrict<ChromeEventProcessingWindow>( |
| 80 [GetNativeView() window]); |
| 81 [event_window redispatchKeyEvent:event.os_event]; |
| 82 } |
| 83 |
| 84 void ExtensionViewMac::DidStopLoading() { |
| 85 ShowIfCompletelyLoaded(); |
| 86 } |
| 87 |
| 88 content::RenderViewHost* ExtensionViewMac::render_view_host() const { |
| 89 return extension_host_->render_view_host(); |
68 } | 90 } |
69 | 91 |
70 void ExtensionViewMac::CreateWidgetHostView() { | 92 void ExtensionViewMac::CreateWidgetHostView() { |
71 extension_host_->CreateRenderViewSoon(); | 93 extension_host_->CreateRenderViewSoon(); |
72 } | 94 } |
73 | 95 |
74 void ExtensionViewMac::ShowIfCompletelyLoaded() { | 96 void ExtensionViewMac::ShowIfCompletelyLoaded() { |
75 // We wait to show the ExtensionView until it has loaded, and the view has | 97 // We wait to show the ExtensionView until it has loaded, and the view has |
76 // actually been created. These can happen in different orders. | 98 // actually been created. These can happen in different orders. |
77 if (extension_host_->did_stop_loading()) { | 99 if (extension_host_->did_stop_loading()) { |
78 [native_view() setHidden:NO]; | 100 [GetNativeView() setHidden:NO]; |
79 if (container_) | 101 if (container_) |
80 container_->OnExtensionViewDidShow(this); | 102 container_->OnExtensionViewDidShow(this); |
81 } | 103 } |
82 } | 104 } |
| 105 |
| 106 namespace extensions { |
| 107 |
| 108 // static |
| 109 scoped_ptr<ExtensionView> ExtensionViewHost::CreateExtensionView( |
| 110 ExtensionViewHost* host, |
| 111 Browser* browser) { |
| 112 scoped_ptr<ExtensionViewMac> view(new ExtensionViewMac(host, browser)); |
| 113 return view.PassAs<ExtensionView>(); |
| 114 } |
| 115 |
| 116 } // namespace extensions |
OLD | NEW |