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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_view_mac.mm

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

Powered by Google App Engine
This is Rietveld 408576698