| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/webwidget_host.h" | 7 #include "webkit/tools/test_shell/webwidget_host.h" |
| 8 | 8 |
| 9 #include "base/gfx/platform_canvas_mac.h" | 9 #include "base/gfx/platform_canvas_mac.h" |
| 10 #include "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
| 11 #include "base/gfx/size.h" | 11 #include "base/gfx/size.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/mac/WebScreenInfoFactory.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" |
| 15 #include "webkit/glue/webwidget.h" | 17 #include "webkit/glue/webwidget.h" |
| 16 #include "webkit/tools/test_shell/test_shell.h" | 18 #include "webkit/tools/test_shell/test_shell.h" |
| 17 | 19 |
| 18 using WebKit::WebInputEvent; | 20 using WebKit::WebInputEvent; |
| 19 using WebKit::WebInputEventFactory; | 21 using WebKit::WebInputEventFactory; |
| 20 using WebKit::WebKeyboardEvent; | 22 using WebKit::WebKeyboardEvent; |
| 21 using WebKit::WebMouseEvent; | 23 using WebKit::WebMouseEvent; |
| 22 using WebKit::WebMouseWheelEvent; | 24 using WebKit::WebMouseWheelEvent; |
| 25 using WebKit::WebScreenInfo; |
| 26 using WebKit::WebScreenInfoFactory; |
| 23 | 27 |
| 24 /*static*/ | 28 /*static*/ |
| 25 WebWidgetHost* WebWidgetHost::Create(NSView* parent_view, | 29 WebWidgetHost* WebWidgetHost::Create(NSView* parent_view, |
| 26 WebWidgetDelegate* delegate) { | 30 WebWidgetDelegate* delegate) { |
| 27 WebWidgetHost* host = new WebWidgetHost(); | 31 WebWidgetHost* host = new WebWidgetHost(); |
| 28 | 32 |
| 29 NSRect content_rect = [parent_view frame]; | 33 NSRect content_rect = [parent_view frame]; |
| 30 content_rect.origin.y += 64; | 34 content_rect.origin.y += 64; |
| 31 content_rect.size.height -= 64; | 35 content_rect.size.height -= 64; |
| 32 host->view_ = [[NSView alloc] initWithFrame:content_rect]; | 36 host->view_ = [[NSView alloc] initWithFrame:content_rect]; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 int bitmap_width = CGBitmapContextGetWidth(bitmap_context); | 211 int bitmap_width = CGBitmapContextGetWidth(bitmap_context); |
| 208 CGRect bitmap_rect = { { 0, 0 }, | 212 CGRect bitmap_rect = { { 0, 0 }, |
| 209 { bitmap_width, bitmap_height } }; | 213 { bitmap_width, bitmap_height } }; |
| 210 canvas_->getTopPlatformDevice().DrawToContext( | 214 canvas_->getTopPlatformDevice().DrawToContext( |
| 211 context, 0, client_rect.height() - bitmap_height, &bitmap_rect); | 215 context, 0, client_rect.height() - bitmap_height, &bitmap_rect); |
| 212 | 216 |
| 213 [view_ unlockFocus]; | 217 [view_ unlockFocus]; |
| 214 } | 218 } |
| 215 } | 219 } |
| 216 | 220 |
| 221 WebScreenInfo WebWidgetHost::GetScreenInfo() { |
| 222 return WebScreenInfoFactory::screenInfo(view_); |
| 223 } |
| 224 |
| 217 void WebWidgetHost::Resize(const gfx::Rect& rect) { | 225 void WebWidgetHost::Resize(const gfx::Rect& rect) { |
| 218 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. | 226 // Force an entire re-paint. TODO(darin): Maybe reuse this memory buffer. |
| 219 DiscardBackingStore(); | 227 DiscardBackingStore(); |
| 220 webwidget_->Resize(gfx::Size(rect.width(), rect.height())); | 228 webwidget_->Resize(gfx::Size(rect.width(), rect.height())); |
| 221 } | 229 } |
| 222 | 230 |
| 223 void WebWidgetHost::MouseEvent(NSEvent *event) { | 231 void WebWidgetHost::MouseEvent(NSEvent *event) { |
| 224 const WebMouseEvent& web_event = WebInputEventFactory::mouseEvent( | 232 const WebMouseEvent& web_event = WebInputEventFactory::mouseEvent( |
| 225 event, view_); | 233 event, view_); |
| 226 switch (web_event.type) { | 234 switch (web_event.type) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 275 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
| 268 #ifndef NDEBUG | 276 #ifndef NDEBUG |
| 269 DCHECK(!painting_); | 277 DCHECK(!painting_); |
| 270 #endif | 278 #endif |
| 271 DCHECK(canvas_.get()); | 279 DCHECK(canvas_.get()); |
| 272 | 280 |
| 273 set_painting(true); | 281 set_painting(true); |
| 274 webwidget_->Paint(canvas_.get(), rect); | 282 webwidget_->Paint(canvas_.get(), rect); |
| 275 set_painting(false); | 283 set_painting(false); |
| 276 } | 284 } |
| OLD | NEW |