| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // origin is the upper-left corner of this view. On the other hand, Cocoa | 268 // origin is the upper-left corner of this view. On the other hand, Cocoa |
| 269 // uses a coordinate system whose origin is the lower-left corner of this | 269 // uses a coordinate system whose origin is the lower-left corner of this |
| 270 // view. So, we convert the cursor rectangle and save it. | 270 // view. So, we convert the cursor rectangle and save it. |
| 271 NSRect view_rect = [cocoa_view_ bounds]; | 271 NSRect view_rect = [cocoa_view_ bounds]; |
| 272 const int y_offset = static_cast<int>(view_rect.size.height); | 272 const int y_offset = static_cast<int>(view_rect.size.height); |
| 273 im_caret_rect_ = NSMakeRect(caret_rect.x(), | 273 im_caret_rect_ = NSMakeRect(caret_rect.x(), |
| 274 y_offset - caret_rect.y() - caret_rect.height(), | 274 y_offset - caret_rect.y() - caret_rect.height(), |
| 275 caret_rect.width(), caret_rect.height()); | 275 caret_rect.width(), caret_rect.height()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void RenderWidgetHostViewMac::DidPaintBackingStoreRects( | 278 void RenderWidgetHostViewMac::DidPaintRect(const gfx::Rect& rect) { |
| 279 const std::vector<gfx::Rect>& rects) { | |
| 280 if (is_hidden_) | 279 if (is_hidden_) |
| 281 return; | 280 return; |
| 282 | 281 |
| 283 for (size_t i = 0; i < rects.size(); ++i) { | 282 NSRect ns_rect = [cocoa_view_ RectToNSRect:rect]; |
| 284 NSRect ns_rect = [cocoa_view_ RectToNSRect:rects[i]]; | |
| 285 | 283 |
| 286 if (about_to_validate_and_paint_) { | 284 if (about_to_validate_and_paint_) { |
| 287 // As much as we'd like to use -setNeedsDisplayInRect: here, we can't. | 285 // As much as we'd like to use -setNeedsDisplayInRect: here, we can't. We're |
| 288 // We're in the middle of executing a -drawRect:, and as soon as it | 286 // in the middle of executing a -drawRect:, and as soon as it returns Cocoa |
| 289 // returns Cocoa will clear its record of what needs display. If we want | 287 // will clear its record of what needs display. If we want to handle the |
| 290 // to handle the recursive drawing, we need to do it ourselves. | 288 // recursive drawing, we need to do it ourselves. |
| 291 invalid_rect_ = NSUnionRect(invalid_rect_, ns_rect); | 289 invalid_rect_ = NSUnionRect(invalid_rect_, ns_rect); |
| 292 } else { | 290 } else { |
| 293 [cocoa_view_ setNeedsDisplayInRect:ns_rect]; | 291 [cocoa_view_ setNeedsDisplayInRect:ns_rect]; |
| 294 } | 292 [cocoa_view_ displayIfNeeded]; |
| 295 } | 293 } |
| 296 | |
| 297 if (!about_to_validate_and_paint_) | |
| 298 [cocoa_view_ displayIfNeeded]; | |
| 299 } | 294 } |
| 300 | 295 |
| 301 void RenderWidgetHostViewMac::DidScrollBackingStoreRect(const gfx::Rect& rect, | 296 void RenderWidgetHostViewMac::DidScrollRect( |
| 302 int dx, int dy) { | 297 const gfx::Rect& rect, int dx, int dy) { |
| 303 if (is_hidden_) | 298 if (is_hidden_) |
| 304 return; | 299 return; |
| 305 | 300 |
| 306 // We've already modified the BackingStore to reflect the scroll, so | 301 // We've already modified the BackingStore to reflect the scroll, so |
| 307 // simply ask the RWHVCocoa to redraw itself based on the new | 302 // simply ask the RWHVCocoa to redraw itself based on the new |
| 308 // pixels. We cannot use -[NSView scrollRect:by:] here because the | 303 // pixels. We cannot use -[NSView scrollRect:by:] here because the |
| 309 // findbar and blocked popups will leave trails behind. | 304 // findbar and blocked popups will leave trails behind. |
| 310 // TODO(rohitrao): Evaluate how slow this full redraw is. If it | 305 // TODO(rohitrao): Evaluate how slow this full redraw is. If it |
| 311 // turns out to be a problem, consider scrolling only a portion of | 306 // turns out to be a problem, consider scrolling only a portion of |
| 312 // the view, based on where the findbar and blocked popups are. | 307 // the view, based on where the findbar and blocked popups are. |
| 313 DidPaintBackingStoreRects(std::vector<gfx::Rect>(1, rect)); | 308 DidPaintRect(rect); |
| 314 } | 309 } |
| 315 | 310 |
| 316 void RenderWidgetHostViewMac::RenderViewGone() { | 311 void RenderWidgetHostViewMac::RenderViewGone() { |
| 317 // TODO(darin): keep this around, and draw sad-tab into it. | 312 // TODO(darin): keep this around, and draw sad-tab into it. |
| 318 UpdateCursorIfOverSelf(); | 313 UpdateCursorIfOverSelf(); |
| 319 Destroy(); | 314 Destroy(); |
| 320 } | 315 } |
| 321 | 316 |
| 322 void RenderWidgetHostViewMac::Destroy() { | 317 void RenderWidgetHostViewMac::Destroy() { |
| 323 // On Windows, popups are implemented with a popup window style, so that when | 318 // On Windows, popups are implemented with a popup window style, so that when |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 event.skip_in_browser = true; | 1381 event.skip_in_browser = true; |
| 1387 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1382 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1388 } else { | 1383 } else { |
| 1389 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1384 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1390 UTF8ToUTF16([im_text UTF8String])); | 1385 UTF8ToUTF16([im_text UTF8String])); |
| 1391 } | 1386 } |
| 1392 renderWidgetHostView_->im_composing_ = false; | 1387 renderWidgetHostView_->im_composing_ = false; |
| 1393 } | 1388 } |
| 1394 | 1389 |
| 1395 @end | 1390 @end |
| OLD | NEW |