| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "app/surface/io_surface_support_mac.h" | 10 #include "app/surface/io_surface_support_mac.h" |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 shutdown_factory_.RevokeAll(); | 954 shutdown_factory_.RevokeAll(); |
| 955 render_widget_host_->Shutdown(); | 955 render_widget_host_->Shutdown(); |
| 956 // Do not touch any members at this point, |this| has been deleted. | 956 // Do not touch any members at this point, |this| has been deleted. |
| 957 } | 957 } |
| 958 | 958 |
| 959 namespace { | 959 namespace { |
| 960 | 960 |
| 961 // Adjusts an NSRect in Cocoa screen coordinates to have an origin in the upper | 961 // Adjusts an NSRect in Cocoa screen coordinates to have an origin in the upper |
| 962 // left of the primary screen (Carbon coordinates), and stuffs it into a | 962 // left of the primary screen (Carbon coordinates), and stuffs it into a |
| 963 // gfx::Rect. | 963 // gfx::Rect. |
| 964 gfx::Rect flipNSRectToRect(const NSRect rect) { | 964 gfx::Rect FlipNSRectToRectScreen(const NSRect rect) { |
| 965 gfx::Rect new_rect(NSRectToCGRect(rect)); | 965 gfx::Rect new_rect(NSRectToCGRect(rect)); |
| 966 if ([[NSScreen screens] count] > 0) { | 966 if ([[NSScreen screens] count] > 0) { |
| 967 new_rect.set_y([[[NSScreen screens] objectAtIndex:0] frame].size.height - | 967 new_rect.set_y([[[NSScreen screens] objectAtIndex:0] frame].size.height - |
| 968 new_rect.y() - new_rect.height()); | 968 new_rect.y() - new_rect.height()); |
| 969 } | 969 } |
| 970 return new_rect; | 970 return new_rect; |
| 971 } | 971 } |
| 972 | 972 |
| 973 // Returns the window that visually contains the given view. This is different | 973 // Returns the window that visually contains the given view. This is different |
| 974 // from [view window] in the case of tab dragging, where the view's owning | 974 // from [view window] in the case of tab dragging, where the view's owning |
| (...skipping 22 matching lines...) Expand all Loading... |
| 997 // TODO(shess): In case of !window, the view has been removed from | 997 // TODO(shess): In case of !window, the view has been removed from |
| 998 // the view hierarchy because the tab isn't main. Could retrieve | 998 // the view hierarchy because the tab isn't main. Could retrieve |
| 999 // the information from the main tab for our window. | 999 // the information from the main tab for our window. |
| 1000 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); | 1000 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); |
| 1001 if (!enclosing_window) | 1001 if (!enclosing_window) |
| 1002 return gfx::Rect(); | 1002 return gfx::Rect(); |
| 1003 | 1003 |
| 1004 NSRect bounds = [cocoa_view_ bounds]; | 1004 NSRect bounds = [cocoa_view_ bounds]; |
| 1005 bounds = [cocoa_view_ convertRect:bounds toView:nil]; | 1005 bounds = [cocoa_view_ convertRect:bounds toView:nil]; |
| 1006 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin]; | 1006 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin]; |
| 1007 return flipNSRectToRect(bounds); | 1007 return FlipNSRectToRectScreen(bounds); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 gfx::Rect RenderWidgetHostViewMac::GetRootWindowRect() { | 1010 gfx::Rect RenderWidgetHostViewMac::GetRootWindowRect() { |
| 1011 // TODO(shess): In case of !window, the view has been removed from | 1011 // TODO(shess): In case of !window, the view has been removed from |
| 1012 // the view hierarchy because the tab isn't main. Could retrieve | 1012 // the view hierarchy because the tab isn't main. Could retrieve |
| 1013 // the information from the main tab for our window. | 1013 // the information from the main tab for our window. |
| 1014 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); | 1014 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); |
| 1015 if (!enclosing_window) | 1015 if (!enclosing_window) |
| 1016 return gfx::Rect(); | 1016 return gfx::Rect(); |
| 1017 | 1017 |
| 1018 NSRect bounds = [enclosing_window frame]; | 1018 NSRect bounds = [enclosing_window frame]; |
| 1019 return flipNSRectToRect(bounds); | 1019 return FlipNSRectToRectScreen(bounds); |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 void RenderWidgetHostViewMac::SetActive(bool active) { | 1022 void RenderWidgetHostViewMac::SetActive(bool active) { |
| 1023 if (render_widget_host_) | 1023 if (render_widget_host_) |
| 1024 render_widget_host_->SetActive(active); | 1024 render_widget_host_->SetActive(active); |
| 1025 if (HasFocus()) | 1025 if (HasFocus()) |
| 1026 SetTextInputActive(active); | 1026 SetTextInputActive(active); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 void RenderWidgetHostViewMac::SetWindowVisibility(bool visible) { | 1029 void RenderWidgetHostViewMac::SetWindowVisibility(bool visible) { |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 - (void)callSetNeedsDisplayInRect { | 1431 - (void)callSetNeedsDisplayInRect { |
| 1432 DCHECK([NSThread isMainThread]); | 1432 DCHECK([NSThread isMainThread]); |
| 1433 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_); | 1433 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_); |
| 1434 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_]; | 1434 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_]; |
| 1435 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false; | 1435 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false; |
| 1436 renderWidgetHostView_->invalid_rect_ = NSZeroRect; | 1436 renderWidgetHostView_->invalid_rect_ = NSZeroRect; |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 // Fills with white the parts of the area to the right and bottom for |rect| |
| 1440 // that intersect |damagedRect|. |
| 1441 - (void)fillBottomRightRemainderOfRect:(gfx::Rect)rect |
| 1442 dirtyRect:(gfx::Rect)damagedRect { |
| 1443 if (damagedRect.right() > rect.right()) { |
| 1444 int x = std::max(rect.right(), damagedRect.x()); |
| 1445 int y = std::min(rect.bottom(), damagedRect.bottom()); |
| 1446 int width = damagedRect.right() - x; |
| 1447 int height = damagedRect.y() - y; |
| 1448 |
| 1449 // Extra fun to get around the fact that gfx::Rects can't have |
| 1450 // negative sizes. |
| 1451 if (width < 0) { |
| 1452 x += width; |
| 1453 width = -width; |
| 1454 } |
| 1455 if (height < 0) { |
| 1456 y += height; |
| 1457 height = -height; |
| 1458 } |
| 1459 |
| 1460 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
| 1461 [[NSColor whiteColor] set]; |
| 1462 NSRectFill(r); |
| 1463 } |
| 1464 if (damagedRect.bottom() > rect.bottom()) { |
| 1465 int x = damagedRect.x(); |
| 1466 int y = damagedRect.bottom(); |
| 1467 int width = damagedRect.right() - x; |
| 1468 int height = std::max(rect.bottom(), damagedRect.y()) - y; |
| 1469 |
| 1470 // Extra fun to get around the fact that gfx::Rects can't have |
| 1471 // negative sizes. |
| 1472 if (width < 0) { |
| 1473 x += width; |
| 1474 width = -width; |
| 1475 } |
| 1476 if (height < 0) { |
| 1477 y += height; |
| 1478 height = -height; |
| 1479 } |
| 1480 |
| 1481 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
| 1482 [[NSColor whiteColor] set]; |
| 1483 NSRectFill(r); |
| 1484 } |
| 1485 } |
| 1486 |
| 1439 - (void)drawRect:(NSRect)dirtyRect { | 1487 - (void)drawRect:(NSRect)dirtyRect { |
| 1440 if (!renderWidgetHostView_->render_widget_host_) { | 1488 if (!renderWidgetHostView_->render_widget_host_) { |
| 1441 // TODO(shess): Consider using something more noticable? | 1489 // TODO(shess): Consider using something more noticable? |
| 1442 [[NSColor whiteColor] set]; | 1490 [[NSColor whiteColor] set]; |
| 1443 NSRectFill(dirtyRect); | 1491 NSRectFill(dirtyRect); |
| 1444 return; | 1492 return; |
| 1445 } | 1493 } |
| 1446 | 1494 |
| 1495 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); |
| 1496 |
| 1447 if (renderWidgetHostView_->render_widget_host_->is_gpu_rendering_active()) { | 1497 if (renderWidgetHostView_->render_widget_host_->is_gpu_rendering_active()) { |
| 1498 gfx::Rect gpuRect; |
| 1499 |
| 1500 gfx::PluginWindowHandle root_handle = |
| 1501 renderWidgetHostView_->plugin_container_manager_.root_container_handle(); |
| 1502 if (root_handle != gfx::kNullPluginWindow) { |
| 1503 RenderWidgetHostViewMac::PluginViewMap::iterator it = |
| 1504 renderWidgetHostView_->plugin_views_.find(root_handle); |
| 1505 DCHECK(it != renderWidgetHostView_->plugin_views_.end()); |
| 1506 if (it != renderWidgetHostView_->plugin_views_.end() && |
| 1507 ![it->second isHidden]) { |
| 1508 gpuRect = [self flipNSRectToRect:[it->second frame]]; |
| 1509 } |
| 1510 } |
| 1511 |
| 1512 [self fillBottomRightRemainderOfRect:gpuRect dirtyRect:damagedRect]; |
| 1448 return; | 1513 return; |
| 1449 } | 1514 } |
| 1450 | 1515 |
| 1451 DCHECK( | 1516 DCHECK( |
| 1452 renderWidgetHostView_->render_widget_host_->process()->HasConnection()); | 1517 renderWidgetHostView_->render_widget_host_->process()->HasConnection()); |
| 1453 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); | 1518 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); |
| 1454 | 1519 |
| 1455 renderWidgetHostView_->about_to_validate_and_paint_ = true; | 1520 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
| 1456 BackingStoreMac* backing_store = static_cast<BackingStoreMac*>( | 1521 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( |
| 1457 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); | 1522 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); |
| 1458 renderWidgetHostView_->about_to_validate_and_paint_ = false; | 1523 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
| 1459 | 1524 |
| 1460 if (backing_store) { | 1525 if (backingStore) { |
| 1461 NSRect view_bounds = [self bounds]; | 1526 gfx::Rect bitmapRect(0, 0, |
| 1462 gfx::Rect damaged_rect([self flipNSRectToRect:dirtyRect]); | 1527 backingStore->size().width(), |
| 1463 | 1528 backingStore->size().height()); |
| 1464 gfx::Rect bitmap_rect(0, 0, | |
| 1465 backing_store->size().width(), | |
| 1466 backing_store->size().height()); | |
| 1467 | 1529 |
| 1468 // Specify the proper y offset to ensure that the view is rooted to the | 1530 // Specify the proper y offset to ensure that the view is rooted to the |
| 1469 // upper left corner. This can be negative, if the window was resized | 1531 // upper left corner. This can be negative, if the window was resized |
| 1470 // smaller and the renderer hasn't yet repainted. | 1532 // smaller and the renderer hasn't yet repainted. |
| 1471 int yOffset = NSHeight(view_bounds) - backing_store->size().height(); | 1533 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); |
| 1472 | 1534 |
| 1473 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); | 1535 gfx::Rect paintRect = bitmapRect.Intersect(damagedRect); |
| 1474 if (!paint_rect.IsEmpty()) { | 1536 if (!paintRect.IsEmpty()) { |
| 1475 // if we have a CGLayer, draw that into the window | 1537 // if we have a CGLayer, draw that into the window |
| 1476 if (backing_store->cg_layer()) { | 1538 if (backingStore->cg_layer()) { |
| 1477 CGContextRef context = static_cast<CGContextRef>( | 1539 CGContextRef context = static_cast<CGContextRef>( |
| 1478 [[NSGraphicsContext currentContext] graphicsPort]); | 1540 [[NSGraphicsContext currentContext] graphicsPort]); |
| 1479 | 1541 |
| 1480 // TODO: add clipping to dirtyRect if it improves drawing performance. | 1542 // TODO: add clipping to dirtyRect if it improves drawing performance. |
| 1481 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset), | 1543 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset), |
| 1482 backing_store->cg_layer()); | 1544 backingStore->cg_layer()); |
| 1483 } else { | 1545 } else { |
| 1484 // if we haven't created a layer yet, draw the cached bitmap into | 1546 // if we haven't created a layer yet, draw the cached bitmap into |
| 1485 // the window. The CGLayer will be created the next time the renderer | 1547 // the window. The CGLayer will be created the next time the renderer |
| 1486 // paints. | 1548 // paints. |
| 1487 CGContextRef context = static_cast<CGContextRef>( | 1549 CGContextRef context = static_cast<CGContextRef>( |
| 1488 [[NSGraphicsContext currentContext] graphicsPort]); | 1550 [[NSGraphicsContext currentContext] graphicsPort]); |
| 1489 scoped_cftyperef<CGImageRef> image( | 1551 scoped_cftyperef<CGImageRef> image( |
| 1490 CGBitmapContextCreateImage(backing_store->cg_bitmap())); | 1552 CGBitmapContextCreateImage(backingStore->cg_bitmap())); |
| 1491 CGRect imageRect = bitmap_rect.ToCGRect(); | 1553 CGRect imageRect = bitmapRect.ToCGRect(); |
| 1492 imageRect.origin.y = yOffset; | 1554 imageRect.origin.y = yOffset; |
| 1493 CGContextDrawImage(context, imageRect, image); | 1555 CGContextDrawImage(context, imageRect, image); |
| 1494 } | 1556 } |
| 1495 } | 1557 } |
| 1496 | 1558 |
| 1497 // Fill the remaining portion of the damaged_rect with white | 1559 // Fill the remaining portion of the damagedRect with white |
| 1498 if (damaged_rect.right() > bitmap_rect.right()) { | 1560 [self fillBottomRightRemainderOfRect:bitmapRect dirtyRect:damagedRect]; |
| 1499 int x = std::max(bitmap_rect.right(), damaged_rect.x()); | |
| 1500 int y = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); | |
| 1501 int width = damaged_rect.right() - x; | |
| 1502 int height = damaged_rect.y() - y; | |
| 1503 | 1561 |
| 1504 // Extra fun to get around the fact that gfx::Rects can't have | |
| 1505 // negative sizes. | |
| 1506 if (width < 0) { | |
| 1507 x += width; | |
| 1508 width = -width; | |
| 1509 } | |
| 1510 if (height < 0) { | |
| 1511 y += height; | |
| 1512 height = -height; | |
| 1513 } | |
| 1514 | |
| 1515 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | |
| 1516 [[NSColor whiteColor] set]; | |
| 1517 NSRectFill(r); | |
| 1518 } | |
| 1519 if (damaged_rect.bottom() > bitmap_rect.bottom()) { | |
| 1520 int x = damaged_rect.x(); | |
| 1521 int y = damaged_rect.bottom(); | |
| 1522 int width = damaged_rect.right() - x; | |
| 1523 int height = std::max(bitmap_rect.bottom(), damaged_rect.y()) - y; | |
| 1524 | |
| 1525 // Extra fun to get around the fact that gfx::Rects can't have | |
| 1526 // negative sizes. | |
| 1527 if (width < 0) { | |
| 1528 x += width; | |
| 1529 width = -width; | |
| 1530 } | |
| 1531 if (height < 0) { | |
| 1532 y += height; | |
| 1533 height = -height; | |
| 1534 } | |
| 1535 | |
| 1536 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | |
| 1537 [[NSColor whiteColor] set]; | |
| 1538 NSRectFill(r); | |
| 1539 } | |
| 1540 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { | 1562 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { |
| 1541 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 1563 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
| 1542 renderWidgetHostView_->whiteout_start_time_; | 1564 renderWidgetHostView_->whiteout_start_time_; |
| 1543 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 1565 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
| 1544 | 1566 |
| 1545 // Reset the start time to 0 so that we start recording again the next | 1567 // Reset the start time to 0 so that we start recording again the next |
| 1546 // time the backing store is NULL... | 1568 // time the backing store is NULL... |
| 1547 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); | 1569 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); |
| 1548 } | 1570 } |
| 1549 if (!renderWidgetHostView_->tab_switch_paint_time_.is_null()) { | 1571 if (!renderWidgetHostView_->tab_switch_paint_time_.is_null()) { |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 if (!string) return NO; | 2409 if (!string) return NO; |
| 2388 | 2410 |
| 2389 // If the user is currently using an IME, confirm the IME input, | 2411 // If the user is currently using an IME, confirm the IME input, |
| 2390 // and then insert the text from the service, the same as TextEdit and Safari. | 2412 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2391 [self confirmComposition]; | 2413 [self confirmComposition]; |
| 2392 [self insertText:string]; | 2414 [self insertText:string]; |
| 2393 return YES; | 2415 return YES; |
| 2394 } | 2416 } |
| 2395 | 2417 |
| 2396 @end | 2418 @end |
| OLD | NEW |