OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | 5 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
8 #include "content/browser/renderer_host/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
9 #include "content/browser/renderer_host/render_widget_host_view.h" | |
9 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 10 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
11 #include "content/browser/tab_contents/tab_contents.h" | |
12 #include "content/browser/tab_contents/tab_contents_view.h" | |
10 | 13 |
11 // The minimum/maximum dimensions of the popup. | 14 // The minimum/maximum dimensions of the popup. |
12 const CGFloat ExtensionViewMac::kMinWidth = 25.0; | 15 const CGFloat ExtensionViewMac::kMinWidth = 25.0; |
13 const CGFloat ExtensionViewMac::kMinHeight = 25.0; | 16 const CGFloat ExtensionViewMac::kMinHeight = 25.0; |
14 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; | 17 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; |
15 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; | 18 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; |
16 | 19 |
17 ExtensionViewMac::ExtensionViewMac(ExtensionHost* extension_host, | 20 ExtensionViewMac::ExtensionViewMac(ExtensionHost* extension_host, |
18 Browser* browser) | 21 Browser* browser) |
19 : browser_(browser), | 22 : browser_(browser), |
20 extension_host_(extension_host), | 23 extension_host_(extension_host) { |
21 render_widget_host_view_(NULL) { | |
22 DCHECK(extension_host_); | 24 DCHECK(extension_host_); |
23 } | 25 } |
24 | 26 |
25 ExtensionViewMac::~ExtensionViewMac() { | 27 ExtensionViewMac::~ExtensionViewMac() { |
26 if (render_widget_host_view_) | |
27 [render_widget_host_view_->native_view() release]; | |
28 } | 28 } |
29 | 29 |
30 void ExtensionViewMac::Init() { | 30 void ExtensionViewMac::Init() { |
31 CreateWidgetHostView(); | 31 CreateWidgetHostView(); |
32 } | 32 } |
33 | 33 |
34 gfx::NativeView ExtensionViewMac::native_view() { | 34 gfx::NativeView ExtensionViewMac::native_view() { |
35 DCHECK(render_widget_host_view_); | 35 return extension_host_->host_contents()->view()->GetNativeView(); |
36 return render_widget_host_view_->native_view(); | |
37 } | 36 } |
38 | 37 |
39 RenderViewHost* ExtensionViewMac::render_view_host() const { | 38 RenderViewHost* ExtensionViewMac::render_view_host() const { |
40 return extension_host_->render_view_host(); | 39 return extension_host_->render_view_host(); |
41 } | 40 } |
42 | 41 |
43 void ExtensionViewMac::SetBackground(const SkBitmap& background) { | 42 void ExtensionViewMac::SetBackground(const SkBitmap& background) { |
44 DCHECK(render_widget_host_view_); | 43 if (!pending_background_.empty() && render_view_host()->view()) { |
45 if (render_view_host()->IsRenderViewLive()) { | 44 render_view_host()->view()->SetBackground(background); |
46 render_widget_host_view_->SetBackground(background); | |
47 } else { | 45 } else { |
48 pending_background_ = background; | 46 pending_background_ = background; |
49 } | 47 } |
50 } | 48 } |
51 | 49 |
52 void ExtensionViewMac::UpdatePreferredSize(const gfx::Size& new_size) { | 50 void ExtensionViewMac::UpdatePreferredSize(const gfx::Size& new_size) { |
53 // TODO(thakis, erikkay): Windows does some tricks to resize the extension | 51 // TODO(thakis, erikkay): Windows does some tricks to resize the extension |
54 // view not before it's visible. Do something similar here. | 52 // view not before it's visible. Do something similar here. |
55 | 53 |
56 // No need to use CA here, our caller calls us repeatedly to animate the | 54 // No need to use CA here, our caller calls us repeatedly to animate the |
57 // resizing. | 55 // resizing. |
58 NSView* view = native_view(); | 56 NSView* view = extension_host_->render_view_host()->view()->GetNativeView(); |
Matt Perry
2011/11/08 20:21:31
TabContentsViewCocoa doesn't implement setFrameWit
| |
59 NSRect frame = [view frame]; | 57 NSRect frame = [view frame]; |
60 frame.size.width = new_size.width(); | 58 frame.size.width = new_size.width(); |
61 frame.size.height = new_size.height(); | 59 frame.size.height = new_size.height(); |
62 | 60 |
63 // |new_size| is in pixels. Convert to view units. | 61 // |new_size| is in pixels. Convert to view units. |
64 frame.size = [view convertSize:frame.size fromView:nil]; | 62 frame.size = [view convertSize:frame.size fromView:nil]; |
65 | 63 |
66 // On first display of some extensions, this function is called with zero | 64 // On first display of some extensions, this function is called with zero |
67 // width after the correct size has been set. Bail if zero is seen, assuming | 65 // width after the correct size has been set. Bail if zero is seen, assuming |
68 // that an extension's view doesn't want any dimensions to ever be zero. | 66 // that an extension's view doesn't want any dimensions to ever be zero. |
(...skipping 15 matching lines...) Expand all Loading... | |
84 void ExtensionViewMac::RenderViewCreated() { | 82 void ExtensionViewMac::RenderViewCreated() { |
85 // Do not allow webkit to draw scroll bars on views smaller than | 83 // Do not allow webkit to draw scroll bars on views smaller than |
86 // the largest size view allowed. The view will be resized to make | 84 // the largest size view allowed. The view will be resized to make |
87 // scroll bars unnecessary. Scroll bars change the height of the | 85 // scroll bars unnecessary. Scroll bars change the height of the |
88 // view, so not drawing them is necessary to avoid infinite resizing. | 86 // view, so not drawing them is necessary to avoid infinite resizing. |
89 gfx::Size largest_popup_size( | 87 gfx::Size largest_popup_size( |
90 CGSizeMake(ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight)); | 88 CGSizeMake(ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight)); |
91 extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); | 89 extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); |
92 | 90 |
93 if (!pending_background_.empty() && render_view_host()->view()) { | 91 if (!pending_background_.empty() && render_view_host()->view()) { |
94 render_widget_host_view_->SetBackground(pending_background_); | 92 render_view_host()->view()->SetBackground(pending_background_); |
95 pending_background_.reset(); | 93 pending_background_.reset(); |
96 } | 94 } |
97 } | 95 } |
98 | 96 |
99 void ExtensionViewMac::WindowFrameChanged() { | 97 void ExtensionViewMac::WindowFrameChanged() { |
100 if (render_widget_host_view_) | 98 if (render_view_host()->view()) |
101 render_widget_host_view_->WindowFrameChanged(); | 99 render_view_host()->view()->WindowFrameChanged(); |
102 } | 100 } |
103 | 101 |
104 void ExtensionViewMac::CreateWidgetHostView() { | 102 void ExtensionViewMac::CreateWidgetHostView() { |
105 DCHECK(!render_widget_host_view_); | 103 extension_host_->CreateRenderViewSoon(); |
106 render_widget_host_view_ = new RenderWidgetHostViewMac(render_view_host()); | |
107 | |
108 // The RenderWidgetHostViewMac is owned by its native view, which is created | |
109 // in an autoreleased state. retain it, so that it doesn't immediately | |
110 // disappear. | |
111 [render_widget_host_view_->native_view() retain]; | |
112 | |
113 extension_host_->CreateRenderViewSoon(render_widget_host_view_); | |
114 } | 104 } |
OLD | NEW |