Commit 183b5462 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[CI] TextControlSingleLinePainter

Move painting code out of LayoutTextControlSingleLine::Paint()
into TextControlSingleLinePainter.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I9e9bfb48c4ec4193943da3e1c2172fa9419d8bfe
Reviewed-on: https://chromium-review.googlesource.com/1121682
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571784}
parent fcc66e1c
...@@ -34,12 +34,8 @@ ...@@ -34,12 +34,8 @@
#include "third_party/blink/renderer/core/layout/hit_test_result.h" #include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_analyzer.h" #include "third_party/blink/renderer/core/layout/layout_analyzer.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h" #include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h" #include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/theme_painter.h"
#include "third_party/blink/renderer/platform/fonts/simple_font_data.h" #include "third_party/blink/renderer/platform/fonts/simple_font_data.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
namespace blink { namespace blink {
...@@ -67,37 +63,9 @@ inline HTMLElement* LayoutTextControlSingleLine::InnerSpinButtonElement() ...@@ -67,37 +63,9 @@ inline HTMLElement* LayoutTextControlSingleLine::InnerSpinButtonElement()
ShadowElementNames::SpinButton())); ShadowElementNames::SpinButton()));
} }
// TODO(wangxianzhu): Move this into TextControlSingleLinePainter.
void LayoutTextControlSingleLine::Paint(const PaintInfo& paint_info, void LayoutTextControlSingleLine::Paint(const PaintInfo& paint_info,
const LayoutPoint& paint_offset) const { const LayoutPoint& paint_offset) const {
LayoutTextControl::Paint(paint_info, paint_offset); TextControlSingleLinePainter(*this).Paint(paint_info, paint_offset);
if (ShouldPaintSelfBlockBackground(paint_info.phase) &&
should_draw_caps_lock_indicator_) {
// TODO(wangxianzhu): This display item may have conflicting id with the
// normal background. Should we allocate another DisplayItem::Type?
if (DrawingRecorder::UseCachedDrawingIfPossible(paint_info.context, *this,
paint_info.phase))
return;
LayoutRect contents_rect = ContentBoxRect();
// Center in the block progression direction.
if (IsHorizontalWritingMode())
contents_rect.SetY((Size().Height() - contents_rect.Height()) / 2);
else
contents_rect.SetX((Size().Width() - contents_rect.Width()) / 2);
// Convert the rect into the coords used for painting the content.
AdjustPaintOffsetScope adjustment(*this, paint_info, paint_offset);
const auto& local_paint_info = adjustment.GetPaintInfo();
contents_rect.MoveBy(adjustment.AdjustedPaintOffset());
IntRect snapped_rect = PixelSnappedIntRect(contents_rect);
DrawingRecorder recorder(local_paint_info.context, *this,
local_paint_info.phase);
LayoutTheme::GetTheme().Painter().PaintCapsLockIndicator(
*this, local_paint_info, snapped_rect);
}
} }
void LayoutTextControlSingleLine::UpdateLayout() { void LayoutTextControlSingleLine::UpdateLayout() {
......
...@@ -37,6 +37,9 @@ class LayoutTextControlSingleLine : public LayoutTextControl { ...@@ -37,6 +37,9 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
~LayoutTextControlSingleLine() override; ~LayoutTextControlSingleLine() override;
void CapsLockStateMayHaveChanged(); void CapsLockStateMayHaveChanged();
bool ShouldDrawCapsLockIndicator() const {
return should_draw_caps_lock_indicator_;
}
protected: protected:
Element* ContainerElement() const; Element* ContainerElement() const;
......
...@@ -232,6 +232,8 @@ blink_core_sources("paint") { ...@@ -232,6 +232,8 @@ blink_core_sources("paint") {
"table_row_painter.h", "table_row_painter.h",
"table_section_painter.cc", "table_section_painter.cc",
"table_section_painter.h", "table_section_painter.h",
"text_control_single_line_painter.cc",
"text_control_single_line_painter.h",
"text_paint_style.h", "text_paint_style.h",
"text_painter.cc", "text_painter.cc",
"text_painter.h", "text_painter.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/core/layout/layout_text_control_single_line.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/adjust_paint_offset_scope.h"
#include "third_party/blink/renderer/core/paint/block_painter.h"
#include "third_party/blink/renderer/core/paint/theme_painter.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
namespace blink {
void TextControlSingleLinePainter::Paint(const PaintInfo& paint_info,
const LayoutPoint& paint_offset) {
BlockPainter(text_control_).Paint(paint_info, paint_offset);
if (!ShouldPaintSelfBlockBackground(paint_info.phase) ||
!text_control_.ShouldDrawCapsLockIndicator())
return;
if (DrawingRecorder::UseCachedDrawingIfPossible(
paint_info.context, text_control_, DisplayItem::kCapsLockIndicator))
return;
DrawingRecorder recorder(paint_info.context, text_control_,
DisplayItem::kCapsLockIndicator);
LayoutRect contents_rect = text_control_.ContentBoxRect();
// Center in the block progression direction.
if (text_control_.IsHorizontalWritingMode()) {
contents_rect.SetY(
(text_control_.Size().Height() - contents_rect.Height()) / 2);
} else {
contents_rect.SetX((text_control_.Size().Width() - contents_rect.Width()) /
2);
}
// Convert the rect into the coords used for painting the content.
AdjustPaintOffsetScope adjustment(text_control_, paint_info, paint_offset);
const auto& local_paint_info = adjustment.GetPaintInfo();
contents_rect.MoveBy(adjustment.AdjustedPaintOffset());
IntRect snapped_rect = PixelSnappedIntRect(contents_rect);
LayoutTheme::GetTheme().Painter().PaintCapsLockIndicator(
text_control_, local_paint_info, snapped_rect);
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_TEXT_CONTROL_SINGLE_LINE_PAINTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_TEXT_CONTROL_SINGLE_LINE_PAINTER_H_
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
class LayoutPoint;
class LayoutTextControlSingleLine;
struct PaintInfo;
class TextControlSingleLinePainter {
STACK_ALLOCATED();
public:
TextControlSingleLinePainter(const LayoutTextControlSingleLine& text_control)
: text_control_(text_control) {}
void Paint(const PaintInfo&, const LayoutPoint&);
private:
const LayoutTextControlSingleLine& text_control_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_TEXT_CONTROL_SINGLE_LINE_PAINTER_H_
...@@ -70,6 +70,7 @@ static WTF::String SpecialDrawingTypeAsDebugString(DisplayItem::Type type) { ...@@ -70,6 +70,7 @@ static WTF::String SpecialDrawingTypeAsDebugString(DisplayItem::Type type) {
switch (type) { switch (type) {
DEBUG_STRING_CASE(BoxDecorationBackground); DEBUG_STRING_CASE(BoxDecorationBackground);
DEBUG_STRING_CASE(Caret); DEBUG_STRING_CASE(Caret);
DEBUG_STRING_CASE(CapsLockIndicator);
DEBUG_STRING_CASE(ClippingMask); DEBUG_STRING_CASE(ClippingMask);
DEBUG_STRING_CASE(ColumnRules); DEBUG_STRING_CASE(ColumnRules);
DEBUG_STRING_CASE(DebugDrawing); DEBUG_STRING_CASE(DebugDrawing);
......
...@@ -62,6 +62,7 @@ class PLATFORM_EXPORT DisplayItem { ...@@ -62,6 +62,7 @@ class PLATFORM_EXPORT DisplayItem {
kDrawingPaintPhaseFirst = kDrawingFirst, kDrawingPaintPhaseFirst = kDrawingFirst,
kDrawingPaintPhaseLast = kDrawingFirst + kPaintPhaseMax, kDrawingPaintPhaseLast = kDrawingFirst + kPaintPhaseMax,
kBoxDecorationBackground, kBoxDecorationBackground,
kCapsLockIndicator,
kCaret, kCaret,
kClippingMask, kClippingMask,
kColumnRules, kColumnRules,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment