RenderBR.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2006 Apple Computer, Inc.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #include "config.h"
  22. #include "RenderBR.h"
  23. #include "Document.h"
  24. #include "InlineTextBox.h"
  25. #include "VisiblePosition.h"
  26. namespace WebCore {
  27. static PassRefPtr<StringImpl> newlineString()
  28. {
  29. DEFINE_STATIC_LOCAL(const String, string, (ASCIILiteral("\n")));
  30. return string.impl();
  31. }
  32. RenderBR::RenderBR(Node* node)
  33. : RenderText(node, newlineString())
  34. , m_lineHeight(-1)
  35. {
  36. }
  37. RenderBR::~RenderBR()
  38. {
  39. }
  40. int RenderBR::lineHeight(bool firstLine) const
  41. {
  42. if (firstLine && document()->styleSheetCollection()->usesFirstLineRules()) {
  43. RenderStyle* s = style(firstLine);
  44. if (s != style())
  45. return s->computedLineHeight(view());
  46. }
  47. if (m_lineHeight == -1)
  48. m_lineHeight = style()->computedLineHeight(view());
  49. return m_lineHeight;
  50. }
  51. void RenderBR::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
  52. {
  53. RenderText::styleDidChange(diff, oldStyle);
  54. m_lineHeight = -1;
  55. }
  56. int RenderBR::caretMinOffset() const
  57. {
  58. return 0;
  59. }
  60. int RenderBR::caretMaxOffset() const
  61. {
  62. return 1;
  63. }
  64. VisiblePosition RenderBR::positionForPoint(const LayoutPoint&)
  65. {
  66. return createVisiblePosition(0, DOWNSTREAM);
  67. }
  68. } // namespace WebCore