diff --git a/base/gfx/native_widget_types.h b/base/gfx/native_widget_types.h new file mode 100644 index 00000000000000..fe03f9e3fe7d3f --- /dev/null +++ b/base/gfx/native_widget_types.h @@ -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 +#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_ diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 03242b67feb16f..228b11e34b135e 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -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 rendering_scope(rendering); diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 31de146dbcbf8d..6c2f4ceda655eb 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -29,6 +29,7 @@ #include #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" @@ -63,7 +64,6 @@ struct WindowFeatures; } namespace gfx { -class PlatformCanvasWin; class BitmapPlatformDeviceWin; } @@ -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(); diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index 25e12fdde04f3a..56ab4c9129b90b 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -8,6 +8,7 @@ #include #include "base/basictypes.h" +#include "base/gfx/native_widget_types.h" #include "base/gfx/rect.h" #include "third_party/npapi/bindings/npapi.h" @@ -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; diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 7121ecde2768b2..efe261e89f7a98 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -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" @@ -92,6 +96,7 @@ // Get rid of WTF's pow define so we can use std::pow. #undef pow +#include // for std::pow using namespace WebCore; @@ -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) { @@ -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); @@ -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); } @@ -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); @@ -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(); @@ -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(); @@ -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; } @@ -453,7 +483,9 @@ 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; @@ -461,16 +493,20 @@ bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { // 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; } @@ -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; @@ -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, @@ -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); } @@ -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. @@ -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 } } @@ -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 @@ -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 @@ -1225,9 +1275,15 @@ 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(current_drop_data_.get()), IntPoint(client_x, client_y), IntPoint(screen_x, screen_y), kDropTargetOperation); +#elif defined(OS_MACOSX) + DragData drag_data(reinterpret_cast(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; } @@ -1235,17 +1291,28 @@ bool WebViewImpl::DragTargetDragEnter(const WebDropData& drop_data, 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(current_drop_data_.get()), IntPoint(client_x, client_y), IntPoint(screen_x, screen_y), kDropTargetOperation); +#elif defined(OS_MACOSX) + DragData drag_data(reinterpret_cast(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(current_drop_data_.get()), IntPoint(), IntPoint(), DragOperationNone); +#elif defined(OS_MACOSX) + DragData drag_data(reinterpret_cast(current_drop_data_.get()), + IntPoint(), IntPoint(), DragOperationNone, nil); +#endif page_->dragController()->dragExited(&drag_data); current_drop_data_.reset(NULL); } @@ -1253,9 +1320,15 @@ void WebViewImpl::DragTargetDragLeave() { 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(current_drop_data_.get()), IntPoint(client_x, client_y), IntPoint(screen_x, screen_y), kDropTargetOperation); +#elif defined(OS_MACOSX) + DragData drag_data(reinterpret_cast(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); } @@ -1325,7 +1398,7 @@ void WebViewImpl::ImageResourceDownloadDone(ImageResourceFetcher* fetcher, //----------------------------------------------------------------------------- // WebCore::WidgetClientWin -HWND WebViewImpl::containingWindow() { +gfx::ViewHandle WebViewImpl::containingWindow() { return delegate_ ? delegate_->GetContainingWindow(this) : NULL; } @@ -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() { diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 693b90bdfbbd16..837aed1baf48ba 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -8,6 +8,7 @@ #include #include "base/basictypes.h" +#include "base/gfx/platform_canvas.h" #include "base/gfx/point.h" #include "base/gfx/size.h" #include "webkit/glue/webdropdata.h" @@ -58,7 +59,7 @@ class WebViewImpl : public WebView, virtual void Resize(const gfx::Size& new_size); virtual gfx::Size GetSize() { return size(); } virtual void Layout(); - virtual void Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect); + virtual void Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect); virtual bool HandleInputEvent(const WebInputEvent* input_event); virtual void MouseCaptureLost(); virtual void SetFocus(bool enable); @@ -183,12 +184,12 @@ class WebViewImpl : public WebView, WebViewImpl(); ~WebViewImpl(); - void ModifySelection(UINT message, + void ModifySelection(uint32 message, WebCore::Frame* frame, const WebCore::PlatformKeyboardEvent& e); // WebCore::WidgetClientWin - virtual HWND containingWindow(); + virtual gfx::ViewHandle containingWindow(); virtual void invalidateRect(const WebCore::IntRect& damaged_rect); virtual void scrollRect(int dx, int dy, const WebCore::IntRect& clip_rect); virtual void popupOpened(WebCore::Widget* widget, diff --git a/webkit/glue/webwidget.h b/webkit/glue/webwidget.h index 11c28034fd5b77..8ee0b47bd53c88 100644 --- a/webkit/glue/webwidget.h +++ b/webkit/glue/webwidget.h @@ -5,10 +5,10 @@ #ifndef WEBKIT_GLUE_WEBWIDGET_H__ #define WEBKIT_GLUE_WEBWIDGET_H__ +#include "base/gfx/platform_canvas.h" #include "base/ref_counted.h" namespace gfx { -class PlatformCanvasWin; class Rect; class Size; } @@ -45,7 +45,7 @@ class WebWidget : public base::RefCounted { // multiple times once Layout has been called, assuming no other changes are // made to the WebWidget (e.g., once events are processed, it should be assumed // that another call to Layout is warranted before painting again). - virtual void Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect) = 0; + virtual void Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect) = 0; // Called to inform the WebWidget of an input event. // Returns true if the event has been processed, false otherwise. diff --git a/webkit/glue/webwidget_delegate.h b/webkit/glue/webwidget_delegate.h index ecc21c5b5d5dbb..faf4d0a7ff1a44 100644 --- a/webkit/glue/webwidget_delegate.h +++ b/webkit/glue/webwidget_delegate.h @@ -5,10 +5,9 @@ #ifndef WEBKIT_GLUE_WEBWIDGET_DELEGATE_H__ #define WEBKIT_GLUE_WEBWIDGET_DELEGATE_H__ +#include "base/gfx/native_widget_types.h" #include "webkit/glue/window_open_disposition.h" -typedef struct HWND__* HWND; - namespace gfx { class Point; class Rect; @@ -20,8 +19,8 @@ struct WebPluginGeometry; class WebWidgetDelegate { public: - // Returns the HWND in which the WebWidget is embedded. - virtual HWND GetContainingWindow(WebWidget* webwidget) = 0; + // Returns the view in which the WebWidget is embedded. + virtual gfx::ViewHandle GetContainingWindow(WebWidget* webwidget) = 0; // Called when a region of the WebWidget needs to be re-painted. virtual void DidInvalidateRect(WebWidget* webwidget, const gfx::Rect& rect) = 0; diff --git a/webkit/glue/webwidget_impl.cc b/webkit/glue/webwidget_impl.cc index 64e669a8d6fdb8..36952e081dd0b7 100644 --- a/webkit/glue/webwidget_impl.cc +++ b/webkit/glue/webwidget_impl.cc @@ -16,7 +16,7 @@ #pragma warning(pop) #undef LOG -#include "base/gfx/platform_canvas_win.h" +#include "base/gfx/platform_canvas.h" #include "base/gfx/rect.h" #include "base/logging.h" #include "webkit/glue/event_conversion.h" @@ -119,7 +119,7 @@ void WebWidgetImpl::Resize(const gfx::Size& new_size) { void WebWidgetImpl::Layout() { } -void WebWidgetImpl::Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect) { +void WebWidgetImpl::Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect) { if (!widget_) return; @@ -206,7 +206,7 @@ void WebWidgetImpl::onScrollPositionChanged(Widget* widget) { //----------------------------------------------------------------------------- // WebCore::WidgetClientWin -HWND WebWidgetImpl::containingWindow() { +gfx::ViewHandle WebWidgetImpl::containingWindow() { return delegate_ ? delegate_->GetContainingWindow(this) : NULL; } @@ -241,8 +241,11 @@ void WebWidgetImpl::popupClosed(WebCore::Widget* widget) { } void WebWidgetImpl::setCursor(const WebCore::Cursor& cursor) { +#if defined(OS_WIN) + // TODO(pinkerton): re-enable when WebCursor is ported if (delegate_) delegate_->SetCursor(this, cursor.impl()); +#endif } void WebWidgetImpl::setFocus() { diff --git a/webkit/glue/webwidget_impl.h b/webkit/glue/webwidget_impl.h index a19f3eeba92609..5c706a778c1e0a 100644 --- a/webkit/glue/webwidget_impl.h +++ b/webkit/glue/webwidget_impl.h @@ -6,6 +6,7 @@ #define WEBKIT_GLUE_WEBWIDGET_IMPL_H__ #include "base/basictypes.h" +#include "base/gfx/native_widget_types.h" #include "base/gfx/point.h" #include "base/gfx/size.h" #include "webkit/glue/webwidget.h" @@ -36,7 +37,7 @@ class WebWidgetImpl : public WebWidget, public WebCore::WidgetClientWin { virtual void Resize(const gfx::Size& new_size); virtual gfx::Size GetSize() { return size(); } virtual void Layout(); - virtual void Paint(gfx::PlatformCanvasWin* canvas, const gfx::Rect& rect); + virtual void Paint(gfx::PlatformCanvas* canvas, const gfx::Rect& rect); virtual bool HandleInputEvent(const WebInputEvent* input_event); virtual void MouseCaptureLost(); virtual void SetFocus(bool enable); @@ -71,7 +72,7 @@ class WebWidgetImpl : public WebWidget, public WebCore::WidgetClientWin { ~WebWidgetImpl(); // WebCore::WidgetClientWin - virtual HWND containingWindow(); + virtual gfx::ViewHandle containingWindow(); virtual void invalidateRect(const WebCore::IntRect& damaged_rect); virtual void scrollRect(int dx, int dy, const WebCore::IntRect& clip_rect); virtual void popupOpened(WebCore::Widget* widget, diff --git a/webkit/port/platform/WidgetClientWin.h b/webkit/port/platform/WidgetClientWin.h index d59c529bd26866..50b94452f05561 100644 --- a/webkit/port/platform/WidgetClientWin.h +++ b/webkit/port/platform/WidgetClientWin.h @@ -5,6 +5,7 @@ #ifndef WidgetClientWin_H__ #define WidgetClientWin_H__ +#include "base/gfx/native_widget_types.h" #include "WidgetClient.h" class SkBitmap; @@ -19,7 +20,9 @@ class Range; class WidgetClientWin : public WidgetClient { public: // Returns the containing window for the Widget. - virtual HWND containingWindow() = 0; + // TODO(pinkerton): this needs a better name, "window" is incorrect on other + // platforms. + virtual gfx::ViewHandle containingWindow() = 0; // Invalidate a region of the widget's containing window. virtual void invalidateRect(const IntRect& damagedRect) = 0;