Skip to content

Instantly share code, notes, and snippets.

@kenchris
Created January 31, 2012 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenchris/1710405 to your computer and use it in GitHub Desktop.
Save kenchris/1710405 to your computer and use it in GitHub Desktop.
commit af0f90e234d61a1ad777c53763392ac56d19af7d
Author: Kenneth Rohde Christiansen <kenneth@webkit.org>
Date: Tue Jan 31 11:09:29 2012 +0100
temp
diff --git a/ManualTests/qt/tap-highlighting-inlines.html b/ManualTests/qt/tap-highlighting-inlines.html
index c483952..0c64a3e 100644
--- a/ManualTests/qt/tap-highlighting-inlines.html
+++ b/ManualTests/qt/tap-highlighting-inlines.html
@@ -1,5 +1,8 @@
+<head>
+ <meta name="viewport" content="initial-scale=1">
+</head>
<body>
- <p style="width: 10em; background-color: gray">
+ <p style="width: 10em;">
<a href="">some link</a><br><br>
<a href="">some link breaking lines</a><br><br>
hola mundo! <a href="">a split up link</a><br><br>
diff --git a/Source/WebCore/page/GestureTapHighlighter.cpp b/Source/WebCore/page/GestureTapHighlighter.cpp
index 03c66c0..d70ee84 100644
--- a/Source/WebCore/page/GestureTapHighlighter.cpp
+++ b/Source/WebCore/page/GestureTapHighlighter.cpp
@@ -46,17 +46,17 @@ namespace WebCore {
namespace {
-inline LayoutSize ownerFrameToMainFrameOffset(const RenderObject* o)
+inline LayoutPoint ownerFrameToMainFrameOffset(const RenderObject* o)
{
ASSERT(o->node());
Frame* containingFrame = o->frame();
if (!containingFrame)
- return LayoutSize();
+ return LayoutPoint();
Frame* mainFrame = containingFrame->page()->mainFrame();
LayoutPoint mainFramePoint = mainFrame->view()->rootViewToContents(containingFrame->view()->contentsToRootView(LayoutPoint()));
- return toLayoutSize(mainFramePoint);
+ return mainFramePoint;
}
AffineTransform localToAbsoluteTransform(const RenderObject* o)
@@ -84,6 +84,7 @@ AffineTransform localToAbsoluteTransform(const RenderObject* o)
Path pathForRenderBox(RenderBox* o)
{
ASSERT(o);
+ const int rounding = 4;
LayoutRect contentBox;
LayoutRect paddingBox;
@@ -102,28 +103,89 @@ Path pathForRenderBox(RenderBox* o)
paddingBox.height() + o->borderTop() + o->borderBottom());
FloatRect rect(borderBox);
- rect.inflate(5);
+ rect.inflate(rounding);
- rect.move(ownerFrameToMainFrameOffset(o));
+ rect.move(toLayoutSize(ownerFrameToMainFrameOffset(o)));
Path path;
- path.addRoundedRect(rect, FloatSize(10, 10));
+ FloatSize rounded(rounding * 1.8, rounding * 1.8);
+ path.addRoundedRect(rect, rounded);
return path;
}
-Path pathForRenderInline(RenderInline* o)
+void addRectWithRoundedCorners(Path& path, const LayoutRect& rect, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight)
{
- // FIXME: Adapt this to not just use the bounding box.
- LayoutRect borderBox = o->linesBoundingBox();
+ const int rounding = 4;
- FloatRect rect(borderBox);
- rect.inflate(5);
+ FloatRect copy(rect);
+ copy.inflateX(rounding);
+ copy.inflateY(rounding / 2);
- rect.move(ownerFrameToMainFrameOffset(o));
+ FloatSize rounded(rounding * 1.8, rounding * 1.8);
+ FloatSize squared(0, 0);
+ path.addBeziersForRoundedRect(copy,
+ topLeft ? rounded : squared, topRight ? rounded : squared,
+ bottomLeft ? rounded : squared, bottomRight ? rounded : squared);
+}
+
+inline bool contains(LayoutRect rect, int x)
+{
+ return !rect.isEmpty() && x >= rect.x() && x <= rect.maxX();
+}
+
+Path pathForRenderInline(RenderInline* o)
+{
+ ASSERT(o);
Path path;
- path.addRoundedRect(rect, FloatSize(10, 10));
+
+ Vector<LayoutRect> rects;
+ o->absoluteRects(rects, /* acc. offset */ ownerFrameToMainFrameOffset(o));
+
+ LayoutRect first = rects.size() ? rects.first() : LayoutRect();
+ LayoutRect last = rects.size() > 1 ? rects.last() : LayoutRect();
+ LayoutRect middle;
+ for (int i = 1; i < rects.size() - 1; ++i)
+ middle.uniteIfNonZero(rects.at(i));
+
+ if (!middle.isEmpty()) {
+ int leftSide = middle.x();
+ int rightSide = middle.maxX();
+
+ if (!first.isEmpty()) {
+ leftSide = std::min(leftSide, first.x());
+ rightSide = std::max(rightSide, first.maxX());
+ }
+ if (!last.isEmpty()) {
+ leftSide = std::min(leftSide, last.x());
+ rightSide = std::max(rightSide, last.maxX());
+ }
+
+ middle.setX(leftSide);
+ middle.setWidth(rightSide - leftSide);
+ }
+
+ if (!first.isEmpty()) {
+ addRectWithRoundedCorners(path, first,
+ true, true,
+ !contains(middle, first.x()) && !contains(last, first.x()),
+ !contains(middle, first.maxX()) && !contains(last, first.maxX()));
+ }
+
+ if (!middle.isEmpty()) {
+ addRectWithRoundedCorners(path, middle,
+ !contains(first, middle.x()),
+ false, false,
+ !contains(last, middle.maxX()));
+ }
+
+ if (!last.isEmpty()) {
+ addRectWithRoundedCorners(path, last,
+ !contains(middle, last.x()) && !contains(first, last.x()),
+ !contains(middle, last.maxX()) && !contains(first, last.maxX()),
+ true, true);
+ }
return path;
}
diff --git a/Source/WebCore/platform/graphics/Path.h b/Source/WebCore/platform/graphics/Path.h
index d14d908..69ba93e 100644
--- a/Source/WebCore/platform/graphics/Path.h
+++ b/Source/WebCore/platform/graphics/Path.h
@@ -146,9 +146,9 @@ namespace WebCore {
void apply(void* info, PathApplierFunction) const;
void transform(const AffineTransform&);
- private:
void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
+ private:
PlatformPathPtr m_path;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment