flutter_flutter/engine/public/web/WebFrameClient.h
Adam Barth 3ddae5ea36 Switch KeyboardEvents over to NewEventHandler
This CL moves KeyboardEvents from the old event model to NewEventHandler. This
CL keeps the basic structure of keydown, keypress, keyup events even though
that's a bit wacky. As with pointer and gesture events, this CL removes
PlatformKeyboardEvent in favor of just using WebKeyboardEvent. I've also made
WebKeyboardEvent align more closely with Mojo's keyboard event.

The CL does change one important aspect of key event handling: on the web the
"keyCode" property of KeyboardEvent changes its meaning depending on whether
the event is a keydown or a keypress event. For the former events, keyCode is
the "virtual" (i.e., windows) key code where for the latter events, keyCode is
the character code. To be more precise, I've renamed keyCode to virtualKeyCode
and I've given it a zero (unknown key code) value during keypress events.

R=ojan@chromium.org, eseidel@chromium.org

Review URL: https://codereview.chromium.org/872233002
2015-01-25 22:46:50 -08:00

248 lines
10 KiB
C++

/*
* Copyright (C) 2011, 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_PUBLIC_WEB_WEBFRAMECLIENT_H_
#define SKY_ENGINE_PUBLIC_WEB_WEBFRAMECLIENT_H_
#include "../platform/WebColor.h"
#include "sky/engine/public/platform/WebCommon.h"
#include "sky/engine/public/platform/WebURLError.h"
#include "sky/engine/public/platform/WebURLRequest.h"
#include "sky/engine/public/web/WebFrame.h"
#include "sky/engine/public/web/WebNavigationPolicy.h"
#include "sky/engine/public/web/WebNavigationType.h"
#include "sky/engine/public/web/WebTextDirection.h"
#include "v8/include/v8.h"
namespace mojo {
class View;
}
namespace blink {
class WebCachedURLRequest;
class WebInputEvent;
class WebNode;
class WebString;
class WebURL;
class WebURLLoader;
class WebURLResponse;
struct WebConsoleMessage;
struct WebRect;
struct WebSize;
struct WebURLError;
class WebFrameClient {
public:
// General notifications -----------------------------------------------
// A child frame was created in this frame. This is called when the frame
// is created and initialized. Takes the name of the new frame, the parent
// frame and returns a new WebFrame. The WebFrame is considered in-use
// until frameDetached() is called on it.
// Note: If you override this, you should almost certainly be overriding
// frameDetached().
virtual mojo::View* createChildFrame() { return nullptr; }
// This frame has been detached from the view, but has not been closed yet.
// TODO(mpcomplete): reuse these.
virtual void frameDetached(WebFrame*) { }
// This frame has become focused..
virtual void frameFocused() { }
// This frame is about to be closed. This is called after frameDetached,
// when the document is being unloaded, due to new one committing.
virtual void willClose(WebFrame*) { }
// FIXME(sky): remove.
// Called when a watched CSS selector matches or stops matching.
virtual void didMatchCSS(WebLocalFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) { }
// Console messages ----------------------------------------------------
// Whether or not we should report a detailed message for the given source.
virtual bool shouldReportDetailedMessageForSource(const WebString& source) { return false; }
// A new message was added to the console.
virtual void didAddMessageToConsole(const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine, const WebString& stackTrace) { }
// Load commands -------------------------------------------------------
// The client should handle the navigation externally.
virtual void loadURLExternally(
WebLocalFrame*, const WebURLRequest&, WebNavigationPolicy, const WebString& downloadName) { }
// Navigational queries ------------------------------------------------
// The client may choose to alter the navigation policy. Otherwise,
// defaultPolicy should just be returned.
struct NavigationPolicyInfo {
WebLocalFrame* frame;
const WebURLRequest& urlRequest;
WebNavigationType navigationType;
WebNavigationPolicy defaultPolicy;
bool isTransitionNavigation;
NavigationPolicyInfo(const WebURLRequest& urlRequest)
: frame(0)
, urlRequest(urlRequest)
, navigationType(WebNavigationTypeOther)
, defaultPolicy(WebNavigationPolicyIgnore)
, isTransitionNavigation(false) { }
};
virtual WebNavigationPolicy decidePolicyForNavigation(const NavigationPolicyInfo& info)
{
return info.defaultPolicy;
}
// Navigational notifications ------------------------------------------
// These notifications bracket any loading that occurs in the WebFrame.
virtual void didStartLoading(bool toDifferentDocument) { }
virtual void didStopLoading() { }
// Notification that some progress was made loading the current frame.
// loadProgress is a value between 0 (nothing loaded) and 1.0 (frame fully
// loaded).
virtual void didChangeLoadProgress(double loadProgress) { }
// The document element has been created.
virtual void didCreateDocumentElement(WebLocalFrame*) { }
// The page title is available.
virtual void didReceiveTitle(WebLocalFrame* frame, const WebString& title, WebTextDirection direction) { }
// The 'load' event was dispatched.
virtual void didHandleOnloadEvents(WebLocalFrame*) { }
// The frame's document or one of its subresources failed to load.
virtual void didFailLoad(WebLocalFrame*, const WebURLError&) { }
// The frame's manifest has changed.
virtual void didChangeManifest(WebLocalFrame*) { }
// Transition navigations -----------------------------------------------
// Provides serialized markup of transition elements for use in the following navigation.
virtual void addNavigationTransitionData(const WebString& allowedDestinationOrigin, const WebString& selector, const WebString& markup) { }
// Editing -------------------------------------------------------------
// These methods allow the client to intercept and overrule editing
// operations.
virtual void didChangeSelection(bool isSelectionEmpty) { }
// Low-level resource notifications ------------------------------------
// An element will request a resource.
virtual void willRequestResource(WebLocalFrame*, const WebCachedURLRequest&) { }
// A request is about to be sent out, and the client may modify it. Request
// is writable, and changes to the URL, for example, will change the request
// made. If this request is the result of a redirect, then redirectResponse
// will be non-null and contain the response that triggered the redirect.
virtual void willSendRequest(
WebLocalFrame*, unsigned identifier, WebURLRequest&,
const WebURLResponse& redirectResponse) { }
// Response headers have been received for the resource request given
// by identifier.
virtual void didReceiveResponse(
WebLocalFrame*, unsigned identifier, const WebURLResponse&) { }
virtual void didChangeResourcePriority(
WebLocalFrame* webFrame, unsigned identifier, const WebURLRequest::Priority& priority, int) { }
// The resource request given by identifier succeeded.
virtual void didFinishResourceLoad(
WebLocalFrame*, unsigned identifier) { }
// The specified request was satified from WebCore's memory cache.
virtual void didLoadResourceFromMemoryCache(
WebLocalFrame*, const WebURLRequest&, const WebURLResponse&) { }
// Script notifications ------------------------------------------------
// Notifies that a new script context has been created for this frame.
// This is similar to didClearWindowObject but only called once per
// frame context.
virtual void didCreateScriptContext(WebLocalFrame*, v8::Handle<v8::Context>) { }
// WebKit is about to release its reference to a v8 context for a frame.
virtual void willReleaseScriptContext(WebLocalFrame*, v8::Handle<v8::Context>) { }
// Geometry notifications ----------------------------------------------
// The main frame scrolled.
virtual void didChangeScrollOffset(WebLocalFrame*) { }
// Find-in-page notifications ------------------------------------------
// Notifies how many matches have been found so far, for a given
// identifier. |finalUpdate| specifies whether this is the last update
// (all frames have completed scoping).
virtual void reportFindInPageMatchCount(
int identifier, int count, bool finalUpdate) { }
// Notifies what tick-mark rect is currently selected. The given
// identifier lets the client know which request this message belongs
// to, so that it can choose to ignore the message if it has moved on
// to other things. The selection rect is expected to have coordinates
// relative to the top left corner of the web page area and represent
// where on the screen the selection rect is currently located.
virtual void reportFindInPageSelection(
int identifier, int activeMatchOrdinal, const WebRect& selection) { }
// WebGL ------------------------------------------------------
// Notifies the client that a WebGL context was lost on this page with the
// given reason (one of the GL_ARB_robustness status codes; see
// Extensions3D.h in WebCore/platform/graphics).
virtual void didLoseWebGLContext(WebLocalFrame*, int) { }
protected:
virtual ~WebFrameClient() { }
};
} // namespace blink
#endif // SKY_ENGINE_PUBLIC_WEB_WEBFRAMECLIENT_H_