blob: cb03bc9e85bf351decdbb9c1050db745c2f2deee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/gtk/extension_view_gtk.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
// The minimum/maximum dimensions of the extension view.
// The minimum is just a little larger than the size of a browser action button.
// The maximum is an arbitrary number that should be smaller than most screens.
const int ExtensionViewGtk::kMinWidth = 25;
const int ExtensionViewGtk::kMinHeight = 25;
const int ExtensionViewGtk::kMaxWidth = 800;
const int ExtensionViewGtk::kMaxHeight = 600;
ExtensionViewGtk::ExtensionViewGtk(ExtensionHost* extension_host,
Browser* browser)
: browser_(browser),
extension_host_(extension_host),
render_widget_host_view_(NULL) {
}
void ExtensionViewGtk::Init() {
CreateWidgetHostView();
}
gfx::NativeView ExtensionViewGtk::native_view() {
return render_widget_host_view_->native_view();
}
RenderViewHost* ExtensionViewGtk::render_view_host() const {
return extension_host_->render_view_host();
}
void ExtensionViewGtk::SetBackground(const SkBitmap& background) {
if (render_view_host()->IsRenderViewLive()) {
render_widget_host_view_->SetBackground(background);
} else {
pending_background_ = background;
}
}
void ExtensionViewGtk::UpdatePreferredSize(const gfx::Size& new_size) {
int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width()));
int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height()));
render_widget_host_view_->SetSize(gfx::Size(width, height));
gtk_widget_set_size_request(native_view(), width, height);
}
void ExtensionViewGtk::CreateWidgetHostView() {
DCHECK(!render_widget_host_view_);
render_widget_host_view_ = new RenderWidgetHostViewGtk(render_view_host());
render_widget_host_view_->InitAsChild();
extension_host_->CreateRenderViewSoon(render_widget_host_view_);
}
void ExtensionViewGtk::RenderViewCreated() {
if (!pending_background_.empty() && render_view_host()->view()) {
render_widget_host_view_->SetBackground(pending_background_);
pending_background_.reset();
}
// Tell the renderer not to draw scrollbars in popups unless the
// popups are at the maximum allowed size.
gfx::Size largest_popup_size(ExtensionViewGtk::kMaxWidth,
ExtensionViewGtk::kMaxHeight);
extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size);
}
|