Roll src/third_party/WebKit 3aea697:d9c6159 (svn 201973:201974)
[chromium-blink-merge.git] / components / html_viewer / html_widget.h
blob3935fadc391a38fd6e5e286980659439c0a6f090
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"
12 namespace blink {
13 class WebFrameWidget;
16 namespace mojo {
17 class ApplicationImpl;
18 class View;
21 namespace html_viewer {
23 class GlobalState;
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.
28 class HTMLWidget {
29 public:
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 {
39 public:
40 HTMLWidgetRootRemote();
41 ~HTMLWidgetRootRemote() override;
43 private:
44 // HTMLWidget:
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 {
56 public:
57 struct CreateParams {
58 CreateParams(mojo::ApplicationImpl* app,
59 GlobalState* global_state,
60 mojo::View* view);
61 ~CreateParams();
63 mojo::ApplicationImpl* app;
64 GlobalState* global_state;
65 mojo::View* view;
68 HTMLWidgetRootLocal(CreateParams* create_params);
69 ~HTMLWidgetRootLocal() override;
71 blink::WebView* web_view() { return web_view_; }
73 protected:
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();
86 private:
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);
91 // HTMLWidget:
92 blink::WebWidget* GetWidget() override;
93 void OnViewBoundsChanged(mojo::View* view) override;
95 mojo::ApplicationImpl* app_;
96 GlobalState* global_state_;
97 mojo::View* view_;
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 {
107 public:
108 HTMLWidgetLocalRoot(mojo::ApplicationImpl* app,
109 GlobalState* global_state,
110 mojo::View* view,
111 blink::WebLocalFrame* web_local_frame);
112 ~HTMLWidgetLocalRoot() override;
114 private:
115 // HTMLWidget:
116 blink::WebWidget* GetWidget() override;
117 void OnViewBoundsChanged(mojo::View* view) override;
119 // WebWidgetClient:
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_