1 // Copyright 2015 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 #ifndef COMPONENTS_HTML_VIEWER_HTML_WIDGET_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_WIDGET_H_
8 #include "third_party/WebKit/public/web/WebTextInputInfo.h"
9 #include "third_party/WebKit/public/web/WebViewClient.h"
10 #include "third_party/WebKit/public/web/WebWidgetClient.h"
17 class ApplicationImpl
;
21 namespace html_viewer
{
24 class WebLayerTreeViewImpl
;
26 // HTMLWidget is responsible for creation of the WebWidget. Which WebWidget
27 // and how it is created depends upon the frame the WebWidget is created for.
30 virtual ~HTMLWidget() {}
32 virtual blink::WebWidget
* GetWidget() = 0;
34 virtual void OnViewBoundsChanged(mojo::View
* view
) = 0;
37 // Used for the root frame when the root frame is remote.
38 class HTMLWidgetRootRemote
: public HTMLWidget
{
40 HTMLWidgetRootRemote();
41 ~HTMLWidgetRootRemote() override
;
45 blink::WebWidget
* GetWidget() override
;
46 void OnViewBoundsChanged(mojo::View
* view
) override
;
48 blink::WebView
* web_view_
;
50 DISALLOW_COPY_AND_ASSIGN(HTMLWidgetRootRemote
);
53 // Used for the root frame when the frame is local. If there is only one
54 // frame in the document, this is the HTMLWidget type created.
55 class HTMLWidgetRootLocal
: public HTMLWidget
, public blink::WebViewClient
{
58 CreateParams(mojo::ApplicationImpl
* app
,
59 GlobalState
* global_state
,
63 mojo::ApplicationImpl
* app
;
64 GlobalState
* global_state
;
68 HTMLWidgetRootLocal(CreateParams
* create_params
);
69 ~HTMLWidgetRootLocal() override
;
71 blink::WebView
* web_view() { return web_view_
; }
74 // WebViewClient methods:
75 virtual blink::WebStorageNamespace
* createSessionStorageNamespace();
76 virtual void didCancelCompositionOnSelectionChange();
77 virtual void didChangeContents();
78 virtual void initializeLayerTreeView();
79 virtual blink::WebLayerTreeView
* layerTreeView();
80 virtual void resetInputMethod();
81 virtual void didHandleGestureEvent(const blink::WebGestureEvent
& event
,
82 bool event_cancelled
);
83 virtual void didUpdateTextOfFocusedElementByNonUserInput();
84 virtual void showImeIfNeeded();
87 // Update text input state from WebView to mojo::View. If the focused element
88 // is editable and |show_ime| is True, the software keyboard will be shown.
89 void UpdateTextInputState(bool show_ime
);
92 blink::WebWidget
* GetWidget() override
;
93 void OnViewBoundsChanged(mojo::View
* view
) override
;
95 mojo::ApplicationImpl
* app_
;
96 GlobalState
* global_state_
;
98 blink::WebView
* web_view_
;
99 scoped_ptr
<WebLayerTreeViewImpl
> web_layer_tree_view_impl_
;
100 blink::WebTextInputInfo text_input_info_
;
102 DISALLOW_COPY_AND_ASSIGN(HTMLWidgetRootLocal
);
105 // Used for frames other than the root that are local.
106 class HTMLWidgetLocalRoot
: public HTMLWidget
, public blink::WebWidgetClient
{
108 HTMLWidgetLocalRoot(mojo::ApplicationImpl
* app
,
109 GlobalState
* global_state
,
111 blink::WebLocalFrame
* web_local_frame
);
112 ~HTMLWidgetLocalRoot() override
;
116 blink::WebWidget
* GetWidget() override
;
117 void OnViewBoundsChanged(mojo::View
* view
) override
;
120 virtual void initializeLayerTreeView();
121 virtual blink::WebLayerTreeView
* layerTreeView();
123 mojo::ApplicationImpl
* app_
;
124 GlobalState
* global_state_
;
125 blink::WebFrameWidget
* web_frame_widget_
;
126 scoped_ptr
<WebLayerTreeViewImpl
> web_layer_tree_view_impl_
;
128 DISALLOW_COPY_AND_ASSIGN(HTMLWidgetLocalRoot
);
131 } // namespace html_viewer
133 #endif // COMPONENTS_HTML_VIEWER_HTML_WIDGET_H_