Use lossless compression for CRD icon.
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_android.cc
blobc7e1cbbf1aacef9a08c99e50e8030b790d078918
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
3 // found in the LICENSE file.
5 #include "content/browser/web_contents/web_contents_view_android.h"
7 #include "base/logging.h"
8 #include "content/browser/android/content_view_core_impl.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_view_android.h"
11 #include "content/browser/renderer_host/render_view_host_factory.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/public/browser/web_contents_delegate.h"
16 namespace content {
17 WebContentsView* CreateWebContentsView(
18 WebContentsImpl* web_contents,
19 WebContentsViewDelegate* delegate,
20 RenderViewHostDelegateView** render_view_host_delegate_view) {
21 WebContentsViewAndroid* rv = new WebContentsViewAndroid(
22 web_contents, delegate);
23 *render_view_host_delegate_view = rv;
24 return rv;
27 WebContentsViewAndroid::WebContentsViewAndroid(
28 WebContentsImpl* web_contents,
29 WebContentsViewDelegate* delegate)
30 : web_contents_(web_contents),
31 content_view_core_(NULL),
32 delegate_(delegate) {
35 WebContentsViewAndroid::~WebContentsViewAndroid() {
38 void WebContentsViewAndroid::SetContentViewCore(
39 ContentViewCoreImpl* content_view_core) {
40 content_view_core_ = content_view_core;
41 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
42 web_contents_->GetRenderWidgetHostView());
43 if (rwhv)
44 rwhv->SetContentViewCore(content_view_core_);
46 if (web_contents_->ShowingInterstitialPage()) {
47 rwhv = static_cast<RenderWidgetHostViewAndroid*>(
48 web_contents_->GetInterstitialPage()
49 ->GetMainFrame()
50 ->GetRenderViewHost()
51 ->GetView());
52 if (rwhv)
53 rwhv->SetContentViewCore(content_view_core_);
57 gfx::NativeView WebContentsViewAndroid::GetNativeView() const {
58 return content_view_core_ ? content_view_core_->GetViewAndroid() : NULL;
61 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const {
62 return content_view_core_ ? content_view_core_->GetViewAndroid() : NULL;
65 gfx::NativeWindow WebContentsViewAndroid::GetTopLevelNativeWindow() const {
66 return content_view_core_ ? content_view_core_->GetWindowAndroid() : NULL;
69 void WebContentsViewAndroid::GetContainerBounds(gfx::Rect* out) const {
70 *out = content_view_core_ ? gfx::Rect(content_view_core_->GetViewSize())
71 : gfx::Rect();
74 void WebContentsViewAndroid::SetPageTitle(const base::string16& title) {
75 if (content_view_core_)
76 content_view_core_->SetTitle(title);
79 void WebContentsViewAndroid::SizeContents(const gfx::Size& size) {
80 // TODO(klobag): Do we need to do anything else?
81 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
82 if (rwhv)
83 rwhv->SetSize(size);
86 void WebContentsViewAndroid::Focus() {
87 if (web_contents_->ShowingInterstitialPage())
88 web_contents_->GetInterstitialPage()->Focus();
89 else
90 web_contents_->GetRenderWidgetHostView()->Focus();
93 void WebContentsViewAndroid::SetInitialFocus() {
94 if (web_contents_->FocusLocationBarByDefault())
95 web_contents_->SetFocusToLocationBar(false);
96 else
97 Focus();
100 void WebContentsViewAndroid::StoreFocus() {
101 NOTIMPLEMENTED();
104 void WebContentsViewAndroid::RestoreFocus() {
105 NOTIMPLEMENTED();
108 DropData* WebContentsViewAndroid::GetDropData() const {
109 NOTIMPLEMENTED();
110 return NULL;
113 gfx::Rect WebContentsViewAndroid::GetViewBounds() const {
114 if (content_view_core_)
115 return gfx::Rect(content_view_core_->GetViewSize());
117 return gfx::Rect();
120 void WebContentsViewAndroid::CreateView(
121 const gfx::Size& initial_size, gfx::NativeView context) {
124 RenderWidgetHostViewBase* WebContentsViewAndroid::CreateViewForWidget(
125 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
126 if (render_widget_host->GetView()) {
127 // During testing, the view will already be set up in most cases to the
128 // test view, so we don't want to clobber it with a real one. To verify that
129 // this actually is happening (and somebody isn't accidentally creating the
130 // view twice), we check for the RVH Factory, which will be set when we're
131 // making special ones (which go along with the special views).
132 DCHECK(RenderViewHostFactory::has_factory());
133 return static_cast<RenderWidgetHostViewBase*>(
134 render_widget_host->GetView());
136 // Note that while this instructs the render widget host to reference
137 // |native_view_|, this has no effect without also instructing the
138 // native view (i.e. ContentView) how to obtain a reference to this widget in
139 // order to paint it. See ContentView::GetRenderWidgetHostViewAndroid for an
140 // example of how this is achieved for InterstitialPages.
141 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(render_widget_host);
142 return new RenderWidgetHostViewAndroid(rwhi, content_view_core_);
145 RenderWidgetHostViewBase* WebContentsViewAndroid::CreateViewForPopupWidget(
146 RenderWidgetHost* render_widget_host) {
147 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(render_widget_host);
148 return new RenderWidgetHostViewAndroid(rwhi, NULL);
151 void WebContentsViewAndroid::RenderViewCreated(RenderViewHost* host) {
154 void WebContentsViewAndroid::RenderViewSwappedIn(RenderViewHost* host) {
157 void WebContentsViewAndroid::SetOverscrollControllerEnabled(bool enabled) {
160 void WebContentsViewAndroid::ShowContextMenu(
161 RenderFrameHost* render_frame_host, const ContextMenuParams& params) {
162 if (delegate_)
163 delegate_->ShowContextMenu(render_frame_host, params);
166 void WebContentsViewAndroid::ShowPopupMenu(
167 RenderFrameHost* render_frame_host,
168 const gfx::Rect& bounds,
169 int item_height,
170 double item_font_size,
171 int selected_item,
172 const std::vector<MenuItem>& items,
173 bool right_aligned,
174 bool allow_multiple_selection) {
175 if (content_view_core_) {
176 content_view_core_->ShowSelectPopupMenu(render_frame_host,
177 bounds,
178 items,
179 selected_item,
180 allow_multiple_selection);
184 void WebContentsViewAndroid::HidePopupMenu() {
185 if (content_view_core_)
186 content_view_core_->HideSelectPopupMenu();
189 void WebContentsViewAndroid::StartDragging(
190 const DropData& drop_data,
191 blink::WebDragOperationsMask allowed_ops,
192 const gfx::ImageSkia& image,
193 const gfx::Vector2d& image_offset,
194 const DragEventSourceInfo& event_info) {
195 NOTIMPLEMENTED();
198 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) {
199 NOTIMPLEMENTED();
202 void WebContentsViewAndroid::GotFocus() {
203 // This is only used in the views FocusManager stuff but it bleeds through
204 // all subclasses. http://crbug.com/21875
207 // This is called when we the renderer asks us to take focus back (i.e., it has
208 // iterated past the last focusable element on the page).
209 void WebContentsViewAndroid::TakeFocus(bool reverse) {
210 if (web_contents_->GetDelegate() &&
211 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse))
212 return;
213 web_contents_->GetRenderWidgetHostView()->Focus();
216 } // namespace content