Modified: trunk/Source/WebCore/inspector/DOMNodeHighlighter.cpp (93769 => 93770)
--- trunk/Source/WebCore/inspector/DOMNodeHighlighter.cpp 2011-08-25 10:01:27 UTC (rev 93769)
+++ trunk/Source/WebCore/inspector/DOMNodeHighlighter.cpp 2011-08-25 10:05:13 UTC (rev 93770)
@@ -37,7 +37,6 @@
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsContext.h"
-#include "GraphicsTypes.h"
#include "Node.h"
#include "Page.h"
#include "Range.h"
@@ -50,19 +49,14 @@
namespace {
-#if OS(WINDOWS)
-static const unsigned fontHeightPx = 12;
-#elif OS(MAC_OS_X) || OS(UNIX)
-static const unsigned fontHeightPx = 11;
-#endif
-
const static int rectInflatePx = 4;
+const static int fontHeightPx = 12;
const static int borderWidthPx = 1;
const static int tooltipPadding = 4;
const static int arrowTipOffset = 20;
-const static float arrowHeight = 7;
-const static float arrowHalfWidth = 7;
+const static int arrowHeight = 7;
+const static int arrowHalfWidth = 7;
Path quadToPath(const FloatQuad& quad)
{
@@ -159,49 +153,43 @@
return offset + length;
}
-float calculateArrowTipX(const LayoutRect& anchorBox, const LayoutRect& titleRect)
+int calculateArrowTipX(const LayoutRect& anchorBox, const LayoutRect& titleRect)
{
- const static int anchorTipOffsetPx = 2;
-
- int minX = titleRect.x() + arrowHalfWidth;
- int maxX = titleRect.maxX() - arrowHalfWidth;
int anchorX = anchorBox.x();
- int anchorMaxX = anchorBox.maxX();
- int x = titleRect.x() + arrowTipOffset; // Default tooltip position.
- if (x < anchorX)
- x = anchorX + anchorTipOffsetPx;
- else if (x > anchorMaxX)
- x = anchorMaxX - anchorTipOffsetPx;
+ // Check for heavily misaligned tooltip first.
+ if (titleRect.x() > anchorBox.maxX())
+ return titleRect.x() + arrowHalfWidth;
- if (x < minX)
- x = minX;
- else if (x > maxX)
- x = maxX;
+ if (titleRect.maxX() < anchorX)
+ return titleRect.maxX() - arrowHalfWidth;
+ int x = titleRect.x() + arrowTipOffset;
+ if (x < anchorX)
+ x = anchorX + arrowTipOffset;
+ if (x > titleRect.maxX() - arrowHalfWidth)
+ x = titleRect.maxX() - arrowHalfWidth;
+
return x;
}
-void setUpFontDescription(FontDescription& fontDescription, WebCore::Settings* settings)
+void setUpFontFamilies(FontDescription& fontDescription, WebCore::Settings* settings)
{
#define TOOLTIP_FONT_FAMILIES(size, ...) \
-static const unsigned tooltipFontFaceSize = size;\
+static unsigned tooltipFontFaceSize = size;\
static const AtomicString* tooltipFontFace[size] = { __VA_ARGS__ };
#if OS(WINDOWS)
TOOLTIP_FONT_FAMILIES(2, new AtomicString("Consolas"), new AtomicString("Lucida Console"))
-#elif OS(MAC_OS_X)
-TOOLTIP_FONT_FAMILIES(2, new AtomicString("Menlo"), new AtomicString("Monaco"))
#elif OS(UNIX)
TOOLTIP_FONT_FAMILIES(1, new AtomicString("dejavu sans mono"))
+#elif OS(MAC_OS_X)
+TOOLTIP_FONT_FAMILIES(2, new AtomicString("Menlo"), new AtomicString("Monaco"))
#endif
// In the default case, we get the settings-provided monospace font.
#undef TOOLTIP_FONT_FAMILIES
- fontDescription.setRenderingMode(settings->fontRenderingMode());
- fontDescription.setComputedSize(fontHeightPx);
-
const AtomicString& fixedFontFamily = settings->fixedFontFamily();
if (!fixedFontFamily.isEmpty()) {
fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
@@ -228,7 +216,7 @@
void drawElementTitle(GraphicsContext& context, Node* node, const LayoutRect& boundingBox, const LayoutRect& anchorBox, const FloatRect& overlayRect, WebCore::Settings* settings)
{
- DEFINE_STATIC_LOCAL(Color, backgroundColor, (255, 255, 194));
+ DEFINE_STATIC_LOCAL(Color, backgroundColor, (255, 255, 194, 255));
DEFINE_STATIC_LOCAL(Color, tagColor, (136, 18, 128)); // Same as .webkit-html-tag.
DEFINE_STATIC_LOCAL(Color, attrColor, (26, 26, 166)); // Same as .webkit-html-attribute-value.
DEFINE_STATIC_LOCAL(Color, normalColor, (Color::black));
@@ -277,7 +265,9 @@
nodeTitle += heightNumberPart + pxString;
FontDescription desc;
- setUpFontDescription(desc, settings);
+ desc.setRenderingMode(settings->fontRenderingMode());
+ desc.setComputedSize(fontHeightPx);
+ setUpFontFamilies(desc, settings);
Font font = Font(desc, 0, 0);
font.update(0);
@@ -292,7 +282,7 @@
LayoutUnit dy = borderWidthPx;
// If the tip sticks beyond the right of overlayRect, right-align the tip with the said boundary.
- if (titleRect.maxX() + dx > overlayRect.maxX())
+ if (titleRect.maxX() > overlayRect.maxX())
dx = overlayRect.maxX() - titleRect.maxX();
// If the tip sticks beyond the left of overlayRect, left-align the tip with the said boundary.
@@ -300,7 +290,7 @@
dx = overlayRect.x() - titleRect.x() - borderWidthPx;
// If the tip sticks beyond the bottom of overlayRect, show the tip at top of bounding box.
- if (titleRect.maxY() + dy > overlayRect.maxY()) {
+ if (titleRect.maxY() > overlayRect.maxY()) {
dy = anchorBox.y() - titleRect.maxY() - borderWidthPx;
// If the tip still sticks beyond the bottom of overlayRect, bottom-align the tip with the said boundary.
if (titleRect.maxY() + dy > overlayRect.maxY())
@@ -316,34 +306,26 @@
bool isArrowAtTop = titleRect.y() > anchorBox.y();
titleRect.move(0, tooltipPadding * (isArrowAtTop ? 1 : -1));
+ context.setStrokeColor(pxAndBorderColor, ColorSpaceDeviceRGB);
+ context.setStrokeThickness(borderWidthPx);
+ context.setFillColor(backgroundColor, ColorSpaceDeviceRGB);
+ context.drawRect(titleRect);
+
{
- float arrowTipX = calculateArrowTipX(anchorBox, titleRect);
- int arrowBaseY = isArrowAtTop ? titleRect.y() : titleRect.maxY();
- int arrowOppositeY = isArrowAtTop ? titleRect.maxY() : titleRect.y();
+ int arrowTipX = calculateArrowTipX(anchorBox, titleRect);
+ FloatPoint arrowPoints[3];
+ float arrowBaseY = isArrowAtTop ? titleRect.y() : titleRect.maxY();
+ arrowPoints[0] = FloatPoint(arrowTipX - arrowHalfWidth, arrowBaseY);
+ arrowPoints[1] = FloatPoint(arrowTipX, arrowBaseY + arrowHeight * (isArrowAtTop ? -1 : 1));
+ arrowPoints[2] = FloatPoint(arrowTipX + arrowHalfWidth, arrowBaseY);
+ context.drawConvexPolygon(3, arrowPoints);
- FloatPoint points[8];
- points[0] = FloatPoint(arrowTipX - arrowHalfWidth, arrowBaseY);
- points[1] = FloatPoint(arrowTipX, arrowBaseY + arrowHeight * (isArrowAtTop ? -1 : 1));
- points[2] = FloatPoint(arrowTipX + arrowHalfWidth, arrowBaseY);
- points[3] = FloatPoint(titleRect.maxX(), arrowBaseY);
- points[4] = FloatPoint(titleRect.maxX(), arrowOppositeY);
- points[5] = FloatPoint(titleRect.x(), arrowOppositeY);
- points[6] = FloatPoint(titleRect.x(), arrowBaseY);
- points[7] = points[0];
-
- Path path;
- path.moveTo(points[0]);
- for (int i = 1; i < 8; ++i)
- path.addLineTo(points[i]);
-
- context.save();
- context.translate(0.5, 0.5);
- context.setStrokeColor(pxAndBorderColor, ColorSpaceDeviceRGB);
+ context.setStrokeColor(backgroundColor, ColorSpaceDeviceRGB);
context.setFillColor(backgroundColor, ColorSpaceDeviceRGB);
- context.setStrokeThickness(borderWidthPx);
- context.fillPath(path);
- context.strokePath(path);
- context.restore();
+ context.setStrokeThickness(borderWidthPx + 1);
+ LayoutPoint startPoint = LayoutPoint(arrowPoints[0].x() + 1, arrowPoints[0].y());
+ LayoutPoint endPoint = LayoutPoint(arrowPoints[2].x() - 1, arrowPoints[2].y());
+ context.drawLine(startPoint, endPoint);
}
int currentPos = 0;