Skip to content

Commit

Permalink
platform ifdefs for webview. Add platform_viewdefs to wrap things lik…
Browse files Browse the repository at this point in the history
…e HWNDs to keep APIs more crossplatform. Fix uses of PlatformCanvasWin to just use PlatformCanvas.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1528 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pinkerton@google.com committed Aug 29, 2008
1 parent 6bc9ad9 commit 5429458
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 24 deletions.
38 changes: 38 additions & 0 deletions base/gfx/native_widget_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2008 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.

#ifndef BASE_GFX_NATIVE_WIDGET_TYPES_H_
#define BASE_GFX_NATIVE_WIDGET_TYPES_H_

#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
#ifdef __OBJC__
@class NSView;
@class NSWindow;
@class NSTextField;
#else
class NSView;
class NSWindow;
class NSTextField;
#endif // __OBJC__
#endif // MACOSX

namespace gfx {

#if defined(OS_WIN)
typedef HWND ViewHandle;
typedef HWND WindowHandle;
typedef HWND EditViewHandle;
#elif defined(OS_MACOSX)
typedef NSView *ViewHandle;
typedef NSWindow *WindowHandle;
typedef NSTextField *EditViewHandle;
#endif

} // namespace gfx

#endif // BASE_GFX_NATIVE_WIDGET_TYPES_H_
2 changes: 1 addition & 1 deletion webkit/glue/webframe_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ void WebFrameImpl::Layout() {
FromFrame(child)->Layout();
}

void WebFrameImpl::Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect) {
void WebFrameImpl::Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect) {
static StatsRate rendering(L"WebFramePaintTime");
StatsScope<StatsRate> rendering_scope(rendering);

Expand Down
4 changes: 2 additions & 2 deletions webkit/glue/webframe_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <string>

#include "base/basictypes.h"
#include "base/gfx/platform_canvas.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "webkit/glue/webdatasource_impl.h"
Expand Down Expand Up @@ -63,7 +64,6 @@ struct WindowFeatures;
}

namespace gfx {
class PlatformCanvasWin;
class BitmapPlatformDeviceWin;
}

Expand Down Expand Up @@ -182,7 +182,7 @@ class WebFrameImpl : public WebFrame {

// WebFrameImpl
void Layout();
void Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect);
void Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect);

bool IsLoading();

Expand Down
3 changes: 2 additions & 1 deletion webkit/glue/webplugin_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>

#include "base/basictypes.h"
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
#include "third_party/npapi/bindings/npapi.h"

Expand Down Expand Up @@ -73,7 +74,7 @@ class WebPluginDelegate {

// Returns the window handle for this plugin if it's a windowed plugin,
// or NULL otherwise.
virtual HWND GetWindowHandle() = 0;
virtual gfx::ViewHandle GetWindowHandle() = 0;

virtual void FlushGeometryUpdates() = 0;

Expand Down
86 changes: 81 additions & 5 deletions webkit/glue/webview_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "PluginInfoStore.h"
#if defined(OS_WIN)
#include "RenderThemeWin.h"
#elif defined(OS_MACOSX)
#include "RenderThemeMac.h"
#endif
#include "ResourceHandle.h"
#include "SelectionController.h"
#include "Settings.h"
Expand Down Expand Up @@ -92,6 +96,7 @@

// Get rid of WTF's pow define so we can use std::pow.
#undef pow
#include <cmath> // for std::pow

using namespace WebCore;

Expand Down Expand Up @@ -261,8 +266,8 @@ void WebViewImpl::MouseUp(const WebMouseEvent& event) {
}

void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) {
main_frame_->frame()->eventHandler()->handleWheelEvent(
MakePlatformWheelEvent(main_frame_->frameview(), event));
MakePlatformWheelEvent platform_event(main_frame_->frameview(), event);
main_frame_->frame()->eventHandler()->handleWheelEvent(platform_event);
}

bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
Expand All @@ -285,15 +290,19 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
if (!handler)
return KeyEventDefault(event);

#if defined(OS_WIN)
// TODO(pinkerton): figure out these keycodes on non-windows
if (((event.modifiers == 0) && (event.key_code == VK_APPS)) ||
((event.modifiers == WebInputEvent::SHIFT_KEY) &&
(event.key_code == VK_F10))) {
SendContextMenuEvent(event);
return true;
}
#endif

MakePlatformKeyboardEvent evt(event);

#if defined(OS_WIN)
if (WebInputEvent::KEY_DOWN == event.type) {
MakePlatformKeyboardEvent evt_rawkeydown = evt;
evt_rawkeydown.SetKeyType(WebCore::PlatformKeyboardEvent::RawKeyDown);
Expand All @@ -306,6 +315,19 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
return true;
}
}
#elif defined(OS_MACOSX)
// Windows and Cocoa handle events in rather different ways. On Windows,
// you get two events: WM_KEYDOWN/WM_KEYUP and WM_CHAR. In
// PlatformKeyboardEvent, RawKeyDown represents the raw messages. When
// processing them, we don't process text editing events, since we'll be
// getting the data soon enough. In Cocoa, we get one event with both the
// raw and processed data. Therefore we need to keep the type as KeyDown, so
// that we'll know that this is the only time we'll have the event and that
// we need to do our thing.
if (handler->keyEvent(evt)) {
return true;
}
#endif

return KeyEventDefault(event);
}
Expand Down Expand Up @@ -336,10 +358,12 @@ bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) {
if (!evt.IsCharacterKey())
return true;

#if defined(OS_WIN)
// Safari 3.1 does not pass off WM_SYSCHAR messages to the
// eventHandler::keyEvent. We mimic this behavior.
if (evt.isSystemKey())
return handler->handleAccessKey(evt);
#endif

if (!handler->keyEvent(evt))
return KeyEventDefault(event);
Expand All @@ -355,6 +379,8 @@ bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) {
* function is the code to convert from a Keyboard event to the Right
* Mouse button up event.
*/
#if defined(OS_WIN)
// TODO(pinkerton): implement on non-windows
bool WebViewImpl::SendContextMenuEvent(const WebKeyboardEvent& event) {
static const int kContextMenuMargin = 1;
FrameView* view = page()->mainFrame()->view();
Expand Down Expand Up @@ -431,6 +457,7 @@ bool WebViewImpl::SendContextMenuEvent(const WebKeyboardEvent& event) {
context_menu_allowed_ = false;
return handled;
}
#endif

bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
Frame* frame = GetFocusedWebCoreFrame();
Expand All @@ -439,11 +466,14 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {

switch (event.type) {
case WebInputEvent::CHAR: {
#if defined(OS_WIN)
// TODO(pinkerton): hook this up for non-win32
if (event.key_code == VK_SPACE) {
int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ?
VK_PRIOR : VK_NEXT);
return ScrollViewWithKeyboard(key_code);
}
#endif
break;
}

Expand All @@ -453,24 +483,30 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
case 'A':
GetFocusedFrame()->SelectAll();
return true;
#if defined(OS_WIN)
case VK_INSERT:
#endif
case 'C':
GetFocusedFrame()->Copy();
return true;
// Match FF behavior in the sense that Ctrl+home/end are the only Ctrl
// key combinations which affect scrolling. Safari is buggy in the
// sense that it scrolls the page for all Ctrl+scrolling key
// combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc.
#if defined(OS_WIN)
case VK_HOME:
case VK_END:
#endif
break;
default:
return false;
}
}
#if defined(OS_WIN)
if (!event.system_key) {
return ScrollViewWithKeyboard(event.key_code);
}
#endif
break;
}

Expand All @@ -488,6 +524,7 @@ bool WebViewImpl::ScrollViewWithKeyboard(int key_code) {
ScrollDirection scroll_direction;
ScrollGranularity scroll_granularity;

#if defined(OS_WIN)
switch (key_code) {
case VK_LEFT:
scroll_direction = ScrollLeft;
Expand Down Expand Up @@ -524,6 +561,10 @@ bool WebViewImpl::ScrollViewWithKeyboard(int key_code) {
default:
return false;
}
#elif defined(OS_MACOSX) || defined(OS_LINUX)
scroll_direction = ScrollDown;
scroll_granularity = ScrollByLine;
#endif

bool scroll_handled =
frame->eventHandler()->scrollOverflow(scroll_direction,
Expand Down Expand Up @@ -659,7 +700,7 @@ void WebViewImpl::Layout() {
}
}

void WebViewImpl::Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect) {
void WebViewImpl::Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect) {
if (main_frame_)
main_frame_->Paint(canvas, rect);
}
Expand Down Expand Up @@ -872,7 +913,8 @@ void WebViewImpl::ImeSetComposition(int string_type, int cursor_position,
if (string_length > 0) {
if (target_start < 0) target_start = 0;
if (target_end < 0) target_end = string_length;
WebCore::String composition_string(string_data, string_length);
std::wstring temp(string_data, string_length);
WebCore::String composition_string(webkit_glue::StdWStringToString(temp));
// Create custom underlines.
// To emphasize the selection, the selected region uses a solid black
// for its underline while other regions uses a pale gray for theirs.
Expand All @@ -897,12 +939,14 @@ void WebViewImpl::ImeSetComposition(int string_type, int cursor_position,
editor->setComposition(composition_string, underlines,
cursor_position, cursor_position);
}
#if defined(OS_WIN)
// The given string is a result string, which means the ongoing
// composition has been completed. I have to call the
// Editor::confirmCompletion() and complete this composition.
if (string_type == GCS_RESULTSTR) {
editor->confirmComposition();
}
#endif
}
}

Expand Down Expand Up @@ -971,7 +1015,9 @@ void WebViewImpl::SetInitialFocus(bool reverse) {
keyboard_event.type = WebInputEvent::KEY_DOWN;
if (reverse)
keyboard_event.modifiers = WebInputEvent::SHIFT_KEY;
#if defined(OS_WIN)
keyboard_event.key_code = VK_TAB;
#endif
keyboard_event.key_data = L'\t';
MakePlatformKeyboardEvent platform_event(keyboard_event);
// We have to set the key type explicitly to avoid an assert in the
Expand Down Expand Up @@ -1079,9 +1125,13 @@ void WebViewImpl::SetPreferences(const WebPreferences& preferences) {
settings->setFontRenderingMode(NormalRenderingMode);
settings->setJavaEnabled(preferences.java_enabled);

#if defined(OS_WIN)
// RenderTheme is a singleton that needs to know the default font size to
// draw some form controls. We let it know each time the size changes.
WebCore::RenderThemeWin::setDefaultFontSize(preferences.default_font_size);
#elif defined(OS_MACOSX)
WebCore::RenderThemeMac::setDefaultFontSize(preferences.default_font_size);
#endif

// Used to make sure if the frameview needs layout, layout is triggered
// during Document::updateLayout(). TODO(tc): See bug 1199269 for more
Expand Down Expand Up @@ -1225,37 +1275,60 @@ bool WebViewImpl::DragTargetDragEnter(const WebDropData& drop_data,
*drop_data_copy = drop_data;
current_drop_data_.reset(drop_data_copy);

#if defined(OS_WIN)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation);
#elif defined(OS_MACOSX)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation, nil);
#endif
DragOperation effect = page_->dragController()->dragEntered(&drag_data);
return effect != DragOperationNone;
}

bool WebViewImpl::DragTargetDragOver(
int client_x, int client_y, int screen_x, int screen_y) {
DCHECK(current_drop_data_.get());
#if defined(OS_WIN)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation);
#elif defined(OS_MACOSX)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation, nil);
#endif
DragOperation effect = page_->dragController()->dragUpdated(&drag_data);
return effect != DragOperationNone;
}

void WebViewImpl::DragTargetDragLeave() {
DCHECK(current_drop_data_.get());
#if defined(OS_WIN)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(), IntPoint(), DragOperationNone);
#elif defined(OS_MACOSX)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(), IntPoint(), DragOperationNone, nil);
#endif
page_->dragController()->dragExited(&drag_data);
current_drop_data_.reset(NULL);
}

void WebViewImpl::DragTargetDrop(
int client_x, int client_y, int screen_x, int screen_y) {
DCHECK(current_drop_data_.get());
#if defined(OS_WIN)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation);
#elif defined(OS_MACOSX)
DragData drag_data(reinterpret_cast<DragDataRef>(current_drop_data_.get()),
IntPoint(client_x, client_y), IntPoint(screen_x, screen_y),
kDropTargetOperation, nil);
#endif
page_->dragController()->performDrag(&drag_data);
current_drop_data_.reset(NULL);
}
Expand Down Expand Up @@ -1325,7 +1398,7 @@ void WebViewImpl::ImageResourceDownloadDone(ImageResourceFetcher* fetcher,
//-----------------------------------------------------------------------------
// WebCore::WidgetClientWin

HWND WebViewImpl::containingWindow() {
gfx::ViewHandle WebViewImpl::containingWindow() {
return delegate_ ? delegate_->GetContainingWindow(this) : NULL;
}

Expand Down Expand Up @@ -1361,8 +1434,11 @@ void WebViewImpl::popupClosed(WebCore::Widget* widget) {
}

void WebViewImpl::setCursor(const WebCore::Cursor& cursor) {
#if defined(OS_WIN)
// TODO(pinkerton): figure out the cursor delegate methods
if (delegate_)
delegate_->SetCursor(this, cursor.impl());
#endif
}

void WebViewImpl::setFocus() {
Expand Down
Loading

0 comments on commit 5429458

Please sign in to comment.