Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Unified Diff: Source/core/editing/FrameSelection.cpp

Issue 14098003: Change the caret color according to the lightness of the background color. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: updated patch Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/platform/graphics/Color.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index aa4a95d3d3c4f540af58cdf7384ca816c0017406..2016ea8755934df0daecf7b6380321bbcbbef607 100644
--- a/Source/core/editing/FrameSelection.cpp
+++ b/Source/core/editing/FrameSelection.cpp
@@ -1440,9 +1440,29 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
Color caretColor = Color::black;
ColorSpace colorSpace = ColorSpaceDeviceRGB;
- Element* element = node->rootEditableElement();
+ Element* element = static_cast<Element *>(node);
if (element && element->renderer()) {
- caretColor = element->renderer()->style()->visitedDependentColor(CSSPropertyColor);
+ bool isBackgroundWhite = true;
eseidel 2013/04/27 05:10:42 This doesn't mean "isBackgroundWhite" either. :)
+ RenderObject* renderer = element->renderer();
+ while (renderer) {
eseidel 2013/04/27 05:10:42 I would re-write this as a helper function: Rende
joone 2013/04/29 19:17:28 Okay, I will add this helper function.
+ if (renderer->style()->hasBackground()) {
+ isBackgroundWhite = false;
+ break;
+ }
+ if (!renderer->isRoot())
+ renderer = renderer->parent();
+ else
+ break;
+ }
+
+ Color backgroundColor;
+ if (!isBackgroundWhite) {
+ backgroundColor = renderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
+ if (backgroundColor.lightness() < 0.5)
+ caretColor = Color::white;
+ } else
+ caretColor = Color::black;
+
colorSpace = element->renderer()->style()->colorSpace();
}
« no previous file with comments | « no previous file | Source/core/platform/graphics/Color.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698