OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/paint/InlineFlowBoxPainter.h" | 5 #include "core/paint/InlineFlowBoxPainter.h" |
6 | 6 |
7 #include "core/layout/api/LineLayoutAPIShim.h" | 7 #include "core/layout/api/LineLayoutAPIShim.h" |
8 #include "core/layout/line/RootInlineBox.h" | 8 #include "core/layout/line/RootInlineBox.h" |
9 #include "core/paint/BoxPainter.h" | 9 #include "core/paint/BoxPainter.h" |
| 10 #include "core/paint/NinePieceImagePainter.h" |
10 #include "core/paint/PaintInfo.h" | 11 #include "core/paint/PaintInfo.h" |
11 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
12 #include "platform/graphics/GraphicsContextStateSaver.h" | 13 #include "platform/graphics/GraphicsContextStateSaver.h" |
13 #include "platform/graphics/paint/DrawingRecorder.h" | 14 #include "platform/graphics/paint/DrawingRecorder.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 void InlineFlowBoxPainter::Paint(const PaintInfo& paint_info, | 18 void InlineFlowBoxPainter::Paint(const PaintInfo& paint_info, |
18 const LayoutPoint& paint_offset, | 19 const LayoutPoint& paint_offset, |
19 const LayoutUnit line_top, | 20 const LayoutUnit line_top, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return kPaintBordersWithoutClip; | 235 return kPaintBordersWithoutClip; |
235 | 236 |
236 // We have a border image that spans multiple lines. | 237 // We have a border image that spans multiple lines. |
237 adjusted_clip_rect = PixelSnappedIntRect(ClipRectForNinePieceImageStrip( | 238 adjusted_clip_rect = PixelSnappedIntRect(ClipRectForNinePieceImageStrip( |
238 inline_flow_box_, border_image, adjusted_frame_rect)); | 239 inline_flow_box_, border_image, adjusted_frame_rect)); |
239 return kPaintBordersWithClip; | 240 return kPaintBordersWithClip; |
240 } | 241 } |
241 return kDontPaintBorders; | 242 return kDontPaintBorders; |
242 } | 243 } |
243 | 244 |
| 245 static inline Node* GetNode(const LayoutObject* box_model) { |
| 246 Node* node = nullptr; |
| 247 for (const LayoutObject* obj = box_model; obj && !node; obj = obj->Parent()) |
| 248 node = obj->GeneratingNode(); |
| 249 return node; |
| 250 } |
| 251 |
244 void InlineFlowBoxPainter::PaintBoxDecorationBackground( | 252 void InlineFlowBoxPainter::PaintBoxDecorationBackground( |
245 const PaintInfo& paint_info, | 253 const PaintInfo& paint_info, |
246 const LayoutPoint& paint_offset, | 254 const LayoutPoint& paint_offset, |
247 const LayoutRect& cull_rect) { | 255 const LayoutRect& cull_rect) { |
248 DCHECK(paint_info.phase == kPaintPhaseForeground); | 256 DCHECK(paint_info.phase == kPaintPhaseForeground); |
249 if (inline_flow_box_.GetLineLayoutItem().Style()->Visibility() != | 257 if (inline_flow_box_.GetLineLayoutItem().Style()->Visibility() != |
250 EVisibility::kVisible) | 258 EVisibility::kVisible) |
251 return; | 259 return; |
252 | 260 |
253 // You can use p::first-line to specify a background. If so, the root line | 261 // You can use p::first-line to specify a background. If so, the root line |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 302 |
295 // Shadow comes first and is behind the background and border. | 303 // Shadow comes first and is behind the background and border. |
296 PaintNormalBoxShadow(paint_info, *style_to_use, adjusted_frame_rect); | 304 PaintNormalBoxShadow(paint_info, *style_to_use, adjusted_frame_rect); |
297 | 305 |
298 Color background_color = inline_flow_box_layout_object->ResolveColor( | 306 Color background_color = inline_flow_box_layout_object->ResolveColor( |
299 *style_to_use, CSSPropertyBackgroundColor); | 307 *style_to_use, CSSPropertyBackgroundColor); |
300 PaintFillLayers(paint_info, background_color, | 308 PaintFillLayers(paint_info, background_color, |
301 style_to_use->BackgroundLayers(), adjusted_frame_rect); | 309 style_to_use->BackgroundLayers(), adjusted_frame_rect); |
302 PaintInsetBoxShadow(paint_info, *style_to_use, adjusted_frame_rect); | 310 PaintInsetBoxShadow(paint_info, *style_to_use, adjusted_frame_rect); |
303 | 311 |
| 312 const LayoutObject* box_model = ToLayoutBoxModelObject( |
| 313 LineLayoutAPIShim::LayoutObjectFrom(inline_flow_box_.BoxModelObject())); |
| 314 |
304 switch (border_painting_type) { | 315 switch (border_painting_type) { |
305 case kDontPaintBorders: | 316 case kDontPaintBorders: |
306 break; | 317 break; |
307 case kPaintBordersWithoutClip: | 318 case kPaintBordersWithoutClip: |
308 BoxPainter::PaintBorder( | 319 BoxPainter::PaintBorder( |
309 *ToLayoutBoxModelObject(LineLayoutAPIShim::LayoutObjectFrom( | 320 *box_model, box_model->GetDocument(), GetNode(box_model), paint_info, |
310 inline_flow_box_.BoxModelObject())), | 321 adjusted_frame_rect, |
311 paint_info, adjusted_frame_rect, | |
312 inline_flow_box_.GetLineLayoutItem().StyleRef( | 322 inline_flow_box_.GetLineLayoutItem().StyleRef( |
313 inline_flow_box_.IsFirstLineStyle()), | 323 inline_flow_box_.IsFirstLineStyle()), |
314 kBackgroundBleedNone, inline_flow_box_.IncludeLogicalLeftEdge(), | 324 kBackgroundBleedNone, inline_flow_box_.IncludeLogicalLeftEdge(), |
315 inline_flow_box_.IncludeLogicalRightEdge()); | 325 inline_flow_box_.IncludeLogicalRightEdge()); |
316 break; | 326 break; |
317 case kPaintBordersWithClip: | 327 case kPaintBordersWithClip: |
318 // FIXME: What the heck do we do with RTL here? The math we're using is | 328 // FIXME: What the heck do we do with RTL here? The math we're using is |
319 // obviously not right, but it isn't even clear how this should work at | 329 // obviously not right, but it isn't even clear how this should work at |
320 // all. | 330 // all. |
321 LayoutRect image_strip_paint_rect = PaintRectForImageStrip( | 331 LayoutRect image_strip_paint_rect = PaintRectForImageStrip( |
322 adjusted_paint_offset, frame_rect.Size(), TextDirection::kLtr); | 332 adjusted_paint_offset, frame_rect.Size(), TextDirection::kLtr); |
323 GraphicsContextStateSaver state_saver(paint_info.context); | 333 GraphicsContextStateSaver state_saver(paint_info.context); |
324 paint_info.context.Clip(adjusted_clip_rect); | 334 paint_info.context.Clip(adjusted_clip_rect); |
325 BoxPainter::PaintBorder( | 335 BoxPainter::PaintBorder(*box_model, box_model->GetDocument(), |
326 *ToLayoutBoxModelObject(LineLayoutAPIShim::LayoutObjectFrom( | 336 GetNode(box_model), paint_info, |
327 inline_flow_box_.BoxModelObject())), | 337 image_strip_paint_rect, |
328 paint_info, image_strip_paint_rect, | 338 inline_flow_box_.GetLineLayoutItem().StyleRef( |
329 inline_flow_box_.GetLineLayoutItem().StyleRef( | 339 inline_flow_box_.IsFirstLineStyle())); |
330 inline_flow_box_.IsFirstLineStyle())); | |
331 break; | 340 break; |
332 } | 341 } |
333 } | 342 } |
334 | 343 |
335 void InlineFlowBoxPainter::PaintMask(const PaintInfo& paint_info, | 344 void InlineFlowBoxPainter::PaintMask(const PaintInfo& paint_info, |
336 const LayoutPoint& paint_offset) { | 345 const LayoutPoint& paint_offset) { |
337 if (inline_flow_box_.GetLineLayoutItem().Style()->Visibility() != | 346 if (inline_flow_box_.GetLineLayoutItem().Style()->Visibility() != |
338 EVisibility::kVisible || | 347 EVisibility::kVisible || |
339 paint_info.phase != kPaintPhaseMask) | 348 paint_info.phase != kPaintPhaseMask) |
340 return; | 349 return; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (push_transparency_layer) | 400 if (push_transparency_layer) |
392 paint_info.context.EndLayer(); | 401 paint_info.context.EndLayer(); |
393 return; // Don't paint anything while we wait for the image to load. | 402 return; // Don't paint anything while we wait for the image to load. |
394 } | 403 } |
395 | 404 |
396 LayoutBoxModelObject* box_model = ToLayoutBoxModelObject( | 405 LayoutBoxModelObject* box_model = ToLayoutBoxModelObject( |
397 LineLayoutAPIShim::LayoutObjectFrom(inline_flow_box_.BoxModelObject())); | 406 LineLayoutAPIShim::LayoutObjectFrom(inline_flow_box_.BoxModelObject())); |
398 // The simple case is where we are the only box for this object. In those | 407 // The simple case is where we are the only box for this object. In those |
399 // cases only a single call to draw is required. | 408 // cases only a single call to draw is required. |
400 if (!inline_flow_box_.PrevLineBox() && !inline_flow_box_.NextLineBox()) { | 409 if (!inline_flow_box_.PrevLineBox() && !inline_flow_box_.NextLineBox()) { |
401 BoxPainter::PaintNinePieceImage( | 410 NinePieceImagePainter::Paint( |
402 *box_model, paint_info.context, paint_rect, | 411 paint_info.context, *box_model, box_model->GetDocument(), |
| 412 GetNode(box_model), paint_rect, |
403 inline_flow_box_.GetLineLayoutItem().StyleRef(), mask_nine_piece_image, | 413 inline_flow_box_.GetLineLayoutItem().StyleRef(), mask_nine_piece_image, |
404 composite_op); | 414 composite_op); |
405 } else { | 415 } else { |
406 // We have a mask image that spans multiple lines. | 416 // We have a mask image that spans multiple lines. |
407 // FIXME: What the heck do we do with RTL here? The math we're using is | 417 // FIXME: What the heck do we do with RTL here? The math we're using is |
408 // obviously not right, but it isn't even clear how this should work at all. | 418 // obviously not right, but it isn't even clear how this should work at all. |
409 LayoutRect image_strip_paint_rect = PaintRectForImageStrip( | 419 LayoutRect image_strip_paint_rect = PaintRectForImageStrip( |
410 adjusted_paint_offset, frame_rect.Size(), TextDirection::kLtr); | 420 adjusted_paint_offset, frame_rect.Size(), TextDirection::kLtr); |
411 FloatRect clip_rect(ClipRectForNinePieceImageStrip( | 421 FloatRect clip_rect(ClipRectForNinePieceImageStrip( |
412 inline_flow_box_, mask_nine_piece_image, paint_rect)); | 422 inline_flow_box_, mask_nine_piece_image, paint_rect)); |
413 GraphicsContextStateSaver state_saver(paint_info.context); | 423 GraphicsContextStateSaver state_saver(paint_info.context); |
414 // TODO(chrishtr): this should be pixel-snapped. | 424 // TODO(chrishtr): this should be pixel-snapped. |
415 paint_info.context.Clip(clip_rect); | 425 paint_info.context.Clip(clip_rect); |
416 BoxPainter::PaintNinePieceImage( | 426 NinePieceImagePainter::Paint( |
417 *box_model, paint_info.context, image_strip_paint_rect, | 427 paint_info.context, *box_model, box_model->GetDocument(), |
| 428 GetNode(box_model), image_strip_paint_rect, |
418 inline_flow_box_.GetLineLayoutItem().StyleRef(), mask_nine_piece_image, | 429 inline_flow_box_.GetLineLayoutItem().StyleRef(), mask_nine_piece_image, |
419 composite_op); | 430 composite_op); |
420 } | 431 } |
421 | 432 |
422 if (push_transparency_layer) | 433 if (push_transparency_layer) |
423 paint_info.context.EndLayer(); | 434 paint_info.context.EndLayer(); |
424 } | 435 } |
425 | 436 |
426 // This method should not be needed. See crbug.com/530659. | 437 // This method should not be needed. See crbug.com/530659. |
427 LayoutRect InlineFlowBoxPainter::FrameRectClampedToLineTopAndBottomIfNeeded() | 438 LayoutRect InlineFlowBoxPainter::FrameRectClampedToLineTopAndBottomIfNeeded() |
(...skipping 19 matching lines...) Expand all Loading... |
447 rect.SetHeight(logical_height); | 458 rect.SetHeight(logical_height); |
448 } else { | 459 } else { |
449 rect.SetX(logical_top); | 460 rect.SetX(logical_top); |
450 rect.SetWidth(logical_height); | 461 rect.SetWidth(logical_height); |
451 } | 462 } |
452 } | 463 } |
453 return rect; | 464 return rect; |
454 } | 465 } |
455 | 466 |
456 } // namespace blink | 467 } // namespace blink |
OLD | NEW |