| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/common/chrome_view_type.h" |
| 10 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 14 #include "content/public/browser/web_contents_view.h" |
| 14 | 15 |
| 15 // The minimum/maximum dimensions of the popup. | 16 // The minimum/maximum dimensions of the popup. |
| 16 const CGFloat ExtensionViewMac::kMinWidth = 25.0; | 17 const CGFloat ExtensionViewMac::kMinWidth = 25.0; |
| 17 const CGFloat ExtensionViewMac::kMinHeight = 25.0; | 18 const CGFloat ExtensionViewMac::kMinHeight = 25.0; |
| 18 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; | 19 const CGFloat ExtensionViewMac::kMaxWidth = 800.0; |
| 19 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; | 20 const CGFloat ExtensionViewMac::kMaxHeight = 600.0; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 void ExtensionViewMac::SetBackground(const SkBitmap& background) { | 50 void ExtensionViewMac::SetBackground(const SkBitmap& background) { |
| 50 if (!pending_background_.empty() && render_view_host()->GetView()) { | 51 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 51 render_view_host()->GetView()->SetBackground(background); | 52 render_view_host()->GetView()->SetBackground(background); |
| 52 } else { | 53 } else { |
| 53 pending_background_ = background; | 54 pending_background_ = background; |
| 54 } | 55 } |
| 55 ShowIfCompletelyLoaded(); | 56 ShowIfCompletelyLoaded(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void ExtensionViewMac::UpdatePreferredSize(const gfx::Size& new_size) { | 59 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { |
| 59 if (container_) | 60 if (container_) |
| 60 container_->OnExtensionPreferredSizeChanged(this, new_size); | 61 container_->OnExtensionSizeChanged(this, new_size); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ExtensionViewMac::RenderViewCreated() { | 64 void ExtensionViewMac::RenderViewCreated() { |
| 64 // Do not allow webkit to draw scroll bars on views smaller than | |
| 65 // the largest size view allowed. The view will be resized to make | |
| 66 // scroll bars unnecessary. Scroll bars change the height of the | |
| 67 // view, so not drawing them is necessary to avoid infinite resizing. | |
| 68 gfx::Size largest_popup_size( | |
| 69 CGSizeMake(ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight)); | |
| 70 extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); | |
| 71 | |
| 72 if (!pending_background_.empty() && render_view_host()->GetView()) { | 65 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 73 render_view_host()->GetView()->SetBackground(pending_background_); | 66 render_view_host()->GetView()->SetBackground(pending_background_); |
| 74 pending_background_.reset(); | 67 pending_background_.reset(); |
| 75 } | 68 } |
| 69 |
| 70 content::ViewType host_type = extension_host_->extension_host_type(); |
| 71 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 72 gfx::Size min_size(ExtensionViewMac::kMinWidth, |
| 73 ExtensionViewMac::kMinHeight); |
| 74 gfx::Size max_size(ExtensionViewMac::kMaxWidth, |
| 75 ExtensionViewMac::kMaxHeight); |
| 76 render_view_host()->EnableAutoResize(min_size, max_size); |
| 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 void ExtensionViewMac::WindowFrameChanged() { | 80 void ExtensionViewMac::WindowFrameChanged() { |
| 79 if (render_view_host()->GetView()) | 81 if (render_view_host()->GetView()) |
| 80 render_view_host()->GetView()->WindowFrameChanged(); | 82 render_view_host()->GetView()->WindowFrameChanged(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void ExtensionViewMac::CreateWidgetHostView() { | 85 void ExtensionViewMac::CreateWidgetHostView() { |
| 84 extension_host_->CreateRenderViewSoon(); | 86 extension_host_->CreateRenderViewSoon(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void ExtensionViewMac::ShowIfCompletelyLoaded() { | 89 void ExtensionViewMac::ShowIfCompletelyLoaded() { |
| 88 // We wait to show the ExtensionView until it has loaded, and the view has | 90 // We wait to show the ExtensionView until it has loaded, and the view has |
| 89 // actually been created. These can happen in different orders. | 91 // actually been created. These can happen in different orders. |
| 90 if (extension_host_->did_stop_loading()) { | 92 if (extension_host_->did_stop_loading()) { |
| 91 [native_view() setHidden:NO]; | 93 [native_view() setHidden:NO]; |
| 92 if (container_) | 94 if (container_) |
| 93 container_->OnExtensionViewDidShow(this); | 95 container_->OnExtensionViewDidShow(this); |
| 94 } | 96 } |
| 95 } | 97 } |
| OLD | NEW |