void TiledDrawingAreaProxy::paint(const IntRect& rect, PlatformDrawingContext context) { if (m_isWaitingForDidSetFrameNotification) { WebPageProxy* page = this->page(); if (!page->isValid()) return; if (page->process()->isLaunching()) return; } adjustVisibleRect(); GraphicsContext gc(context); gc.save(); // Assumes the backing store is painted with the scale transform applied. // Since tile content is already scaled, first revert the scaling from the painter. gc.scale(FloatSize(1 / m_contentsScale, 1 / m_contentsScale)); IntRect dirtyRect = mapFromContents(rect); TiledDrawingAreaTile::Coordinate topLeft = tileCoordinateForPoint(dirtyRect.topLeft()); TiledDrawingAreaTile::Coordinate bottomRight = tileCoordinateForPoint(dirtyRect.bottomRight()); for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) { TiledDrawingAreaTile::Coordinate currentCoordinate(xCoordinate, yCoordinate); RefPtr<TiledDrawingAreaTile> currentTile = tileAt(currentCoordinate); if (currentTile && currentTile->isReadyToPaint()) currentTile->paint(&gc, dirtyRect); } } gc.restore(); }
void TiledBackingStore::paint(GraphicsContext* context, const IntRect& rect) { context->save(); // Assumes the backing store is painted with the scale transform applied. // Since tile content is already scaled, first revert the scaling from the painter. context->scale(FloatSize(1.f / m_contentsScale, 1.f / m_contentsScale)); IntRect dirtyRect = mapFromContents(rect); Tile::Coordinate topLeft = tileCoordinateForPoint(dirtyRect.topLeft()); Tile::Coordinate bottomRight = tileCoordinateForPoint(dirtyRect.bottomRight()); for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) { Tile::Coordinate currentCoordinate(xCoordinate, yCoordinate); RefPtr<Tile> currentTile = tileAt(currentCoordinate); if (currentTile && currentTile->isReadyToPaint()) currentTile->paint(context, dirtyRect); else { IntRect tileRect = tileRectForCoordinate(currentCoordinate); IntRect target = intersection(tileRect, dirtyRect); if (target.isEmpty()) continue; Tile::paintCheckerPattern(context, FloatRect(target)); } } } context->restore(); }
void PlatformScrollbar::paintRectWithBorder(GraphicsContext* context, const IntRect& rect, const Color& innerColor, const Color& outerColor) const { context->drawRect(rect); context->fillRect(rect, Color::gray); Color tmp = context->strokeColor(); context->setStrokeColor(Color::lightGray); context->drawLine( rect.topLeft(), rect.topRight() ); context->drawLine( rect.topLeft(), rect.bottomLeft() ); context->drawLine( rect.topRight(), rect.bottomRight() ); context->drawLine( rect.bottomLeft(), rect.bottomRight() ); IntRect inner( rect.x()+1, rect.y()+1, rect.width()-2, rect.height()-2 ); context->setStrokeColor(Color::darkGray); context->drawLine( inner.topLeft(), inner.topRight() ); context->drawLine( inner.topLeft(), inner.bottomLeft() ); context->drawLine( inner.topRight(), inner.bottomRight() ); context->drawLine( inner.bottomLeft(), inner.bottomRight() ); context->setStrokeColor(tmp); }
void TiledDrawingAreaProxy::createTiles() { IntRect visibleRect = mapFromContents(webViewVisibleRect()); m_previousVisibleRect = visibleRect; if (visibleRect.isEmpty()) return; // Resize tiles on edges in case the contents size has changed. bool didResizeTiles = resizeEdgeTiles(); // Remove tiles outside out current maximum keep rect. dropTilesOutsideRect(calculateKeepRect(visibleRect)); // Cover the cover rect with tiles. IntRect coverRect = calculateCoverRect(visibleRect); // Search for the tile position closest to the viewport center that does not yet contain a tile. // Which position is considered the closest depends on the tileDistance function. double shortestDistance = std::numeric_limits<double>::infinity(); Vector<TiledDrawingAreaTile::Coordinate> tilesToCreate; unsigned requiredTileCount = 0; bool hasVisibleCheckers = false; TiledDrawingAreaTile::Coordinate topLeft = tileCoordinateForPoint(coverRect.topLeft()); TiledDrawingAreaTile::Coordinate bottomRight = tileCoordinateForPoint(coverRect.bottomRight()); for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) { TiledDrawingAreaTile::Coordinate currentCoordinate(xCoordinate, yCoordinate); // Distance is 0 for all currently visible tiles. double distance = tileDistance(visibleRect, currentCoordinate); RefPtr<TiledDrawingAreaTile> tile = tileAt(currentCoordinate); if (!distance && (!tile || !tile->isReadyToPaint())) hasVisibleCheckers = true; if (tile) continue; ++requiredTileCount; if (distance > shortestDistance) continue; if (distance < shortestDistance) { tilesToCreate.clear(); shortestDistance = distance; } tilesToCreate.append(currentCoordinate); } } if (hasVisibleCheckers && shortestDistance > 0) return; // Now construct the tile(s). unsigned tilesToCreateCount = tilesToCreate.size(); for (unsigned n = 0; n < tilesToCreateCount; ++n) createTile(tilesToCreate[n]); requiredTileCount -= tilesToCreateCount; // Paint the content of the newly created tiles. if (tilesToCreateCount || didResizeTiles) updateTileBuffers(); // Keep creating tiles until the whole coverRect is covered. if (requiredTileCount) m_tileCreationTimer.startOneShot(m_tileCreationDelay); }
void TiledBackingStore::createTiles() { if (m_contentsFrozen) return; IntRect visibleRect = mapFromContents(m_client->tiledBackingStoreVisibleRect()); m_previousVisibleRect = visibleRect; if (visibleRect.isEmpty()) return; // Remove tiles that extend outside the current contents rect. dropOverhangingTiles(); IntRect keepRect = visibleRect; keepRect.inflateX(visibleRect.width() * (m_keepAreaMultiplier.width() - 1.f)); keepRect.inflateY(visibleRect.height() * (m_keepAreaMultiplier.height() - 1.f)); keepRect.intersect(contentsRect()); dropTilesOutsideRect(keepRect); IntRect coverRect = visibleRect; coverRect.inflateX(visibleRect.width() * (m_coverAreaMultiplier.width() - 1.f)); coverRect.inflateY(visibleRect.height() * (m_coverAreaMultiplier.height() - 1.f)); coverRect.intersect(contentsRect()); // Search for the tile position closest to the viewport center that does not yet contain a tile. // Which position is considered the closest depends on the tileDistance function. double shortestDistance = std::numeric_limits<double>::infinity(); Vector<Tile::Coordinate> tilesToCreate; unsigned requiredTileCount = 0; Tile::Coordinate topLeft = tileCoordinateForPoint(coverRect.topLeft()); Tile::Coordinate bottomRight = tileCoordinateForPoint(coverRect.bottomRight()); for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) { Tile::Coordinate currentCoordinate(xCoordinate, yCoordinate); if (tileAt(currentCoordinate)) continue; ++requiredTileCount; // Distance is 0 for all currently visible tiles. double distance = tileDistance(visibleRect, currentCoordinate); if (distance > shortestDistance) continue; if (distance < shortestDistance) { tilesToCreate.clear(); shortestDistance = distance; } tilesToCreate.append(currentCoordinate); } } // Now construct the tile(s) unsigned tilesToCreateCount = tilesToCreate.size(); for (unsigned n = 0; n < tilesToCreateCount; ++n) { Tile::Coordinate coordinate = tilesToCreate[n]; setTile(coordinate, Tile::create(this, coordinate)); } requiredTileCount -= tilesToCreateCount; // Paint the content of the newly created tiles if (tilesToCreateCount) updateTileBuffers(); // Keep creating tiles until the whole coverRect is covered. if (requiredTileCount) m_tileCreationTimer->startOneShot(m_tileCreationDelay); }