| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/layout/LayoutTheme.h" | 6 #include "core/input/EventHandler.h" |
| 7 | 7 |
| 8 #include "core/dom/NodeComputedStyle.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Range.h" |
| 10 #include "core/editing/FrameSelection.h" |
| 9 #include "core/frame/FrameView.h" | 11 #include "core/frame/FrameView.h" |
| 12 #include "core/frame/LocalFrame.h" |
| 10 #include "core/html/HTMLDocument.h" | 13 #include "core/html/HTMLDocument.h" |
| 11 #include "core/html/HTMLElement.h" | 14 #include "core/page/AutoscrollController.h" |
| 12 #include "core/page/FocusController.h" | |
| 13 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
| 14 #include "core/style/ComputedStyle.h" | 16 #include "core/testing/CoreTestHelpers.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 17 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/graphics/Color.h" | 18 #include "platform/PlatformMouseEvent.h" |
| 17 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 18 | 20 |
| 19 namespace blink { | 21 namespace blink { |
| 20 | 22 |
| 21 class LayoutThemeTest : public ::testing::Test { | 23 class EventHandlerTest : public ::testing::Test { |
| 22 protected: | 24 protected: |
| 23 void SetUp() override; | 25 void SetUp() override; |
| 24 HTMLDocument& document() const { return *m_document; } | 26 |
| 27 Page& page() const { return m_dummyPageHolder->page(); } |
| 28 Document& document() const { return m_dummyPageHolder->document(); } |
| 29 |
| 25 void setHtmlInnerHTML(const char* htmlContent); | 30 void setHtmlInnerHTML(const char* htmlContent); |
| 26 | 31 |
| 27 private: | 32 private: |
| 28 OwnPtr<DummyPageHolder> m_dummyPageHolder; | 33 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 29 HTMLDocument* m_document; | |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 void LayoutThemeTest::SetUp() | 36 void EventHandlerTest::SetUp() |
| 33 { | 37 { |
| 34 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 38 m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
| 35 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
| 36 ASSERT(m_document); | |
| 37 } | 39 } |
| 38 | 40 |
| 39 void LayoutThemeTest::setHtmlInnerHTML(const char* htmlContent) | 41 void EventHandlerTest::setHtmlInnerHTML(const char* htmlContent) |
| 40 { | 42 { |
| 41 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS
SERT_NO_EXCEPTION); | 43 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS
SERT_NO_EXCEPTION); |
| 42 document().view()->updateLayoutAndStyleForPainting(); | 44 document().view()->updateLayoutAndStyleForPainting(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 inline Color outlineColor(Element* element) | 47 TEST_F(EventHandlerTest, dragSelectionAfterScroll) |
| 46 { | 48 { |
| 47 return element->computedStyle()->visitedDependentColor(CSSPropertyOutlineCol
or); | 49 setHtmlInnerHTML("<style> body { margin: 0px; } .upper { width: 300px; heigh
t: 400px; }" |
| 48 } | 50 ".lower { margin: 0px; width: 300px; height: 400px; } .line { display: b
lock; width: 300px; height: 30px; } </style>" |
| 51 "<div class=\"upper\"></div>" |
| 52 "<div class=\"lower\">" |
| 53 "<span class=\"line\">Line 1</span><span class=\"line\">Line 2</span><sp
an class=\"line\">Line 3</span><span class=\"line\">Line 4</span><span class=\"l
ine\">Line 5</span>" |
| 54 "<span class=\"line\">Line 6</span><span class=\"line\">Line 7</span><sp
an class=\"line\">Line 8</span><span class=\"line\">Line 9</span><span class=\"l
ine\">Line 10</span>" |
| 55 "</div>"); |
| 49 | 56 |
| 50 inline EBorderStyle outlineStyle(Element* element) | 57 FrameView* frameView = document().view(); |
| 51 { | 58 frameView->scrollTo(DoublePoint(0, 400)); |
| 52 return element->computedStyle()->outlineStyle(); | |
| 53 } | |
| 54 | 59 |
| 55 TEST_F(LayoutThemeTest, ChangeFocusRingColor) | 60 PlatformMouseEvent mouseDownEvent( |
| 56 { | 61 IntPoint(0, 0), |
| 57 setHtmlInnerHTML("<span id=span tabIndex=0>Span</span>"); | 62 IntPoint(100, 200), |
| 63 LeftButton, |
| 64 PlatformEvent::MousePressed, |
| 65 1, |
| 66 static_cast<PlatformEvent::Modifiers>(0), |
| 67 WTF::currentTime()); |
| 68 document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent); |
| 58 | 69 |
| 59 Element* span = document().getElementById(AtomicString("span")); | 70 PlatformMouseEvent mouseMoveEvent( |
| 60 EXPECT_NE(nullptr, span); | 71 IntPoint(100, 50), |
| 61 EXPECT_NE(nullptr, span->layoutObject()); | 72 IntPoint(200, 250), |
| 73 LeftButton, |
| 74 PlatformEvent::MouseMoved, |
| 75 1, |
| 76 static_cast<PlatformEvent::Modifiers>(0), |
| 77 WTF::currentTime()); |
| 78 document().frame()->eventHandler().handleMouseMoveEvent(mouseMoveEvent); |
| 62 | 79 |
| 63 Color customColor = makeRGB(123, 145, 167); | 80 page().autoscrollController().animate(WTF::currentTime()); |
| 81 page().animator().serviceScriptedAnimations(WTF::currentTime()); |
| 64 | 82 |
| 65 // Checking unfocused style. | 83 PlatformMouseEvent mouseUpEvent( |
| 66 EXPECT_EQ(BNONE, outlineStyle(span)); | 84 IntPoint(100, 50), |
| 67 EXPECT_NE(customColor, outlineColor(span)); | 85 IntPoint(200, 250), |
| 86 LeftButton, |
| 87 PlatformEvent::MouseReleased, |
| 88 1, |
| 89 static_cast<PlatformEvent::Modifiers>(0), |
| 90 WTF::currentTime()); |
| 91 document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent); |
| 68 | 92 |
| 69 // Do focus. | 93 FrameSelection& selection = document().frame()->selection(); |
| 70 document().page()->focusController().setActive(true); | 94 ASSERT_TRUE(selection.isRange()); |
| 71 document().page()->focusController().setFocused(true); | 95 RefPtrWillBeRawPtr<Range> range = selection.toNormalizedRange(); |
| 72 span->focus(); | 96 ASSERT_TRUE(range.get()); |
| 73 document().view()->updateLayoutAndStyleForPainting(); | 97 EXPECT_EQ("Line 1\nLine 2", range->text()); |
| 74 | |
| 75 // Checking focused style. | |
| 76 EXPECT_NE(BNONE, outlineStyle(span)); | |
| 77 EXPECT_NE(customColor, outlineColor(span)); | |
| 78 | |
| 79 // Change focus ring color. | |
| 80 LayoutTheme::theme().setCustomFocusRingColor(customColor); | |
| 81 Page::platformColorsChanged(); | |
| 82 document().view()->updateLayoutAndStyleForPainting(); | |
| 83 | |
| 84 // Check that the focus ring color is updated. | |
| 85 EXPECT_NE(BNONE, outlineStyle(span)); | |
| 86 EXPECT_EQ(customColor, outlineColor(span)); | |
| 87 } | 98 } |
| 88 | 99 |
| 89 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |