| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void HTMLTextFormControlElement::dispatchBlurEvent(Element* newFocusedElement) | 91 void HTMLTextFormControlElement::dispatchBlurEvent(Element* newFocusedElement) |
| 92 { | 92 { |
| 93 if (supportsPlaceholder()) | 93 if (supportsPlaceholder()) |
| 94 updatePlaceholderVisibility(false); | 94 updatePlaceholderVisibility(false); |
| 95 handleBlurEvent(); | 95 handleBlurEvent(); |
| 96 HTMLFormControlElementWithState::dispatchBlurEvent(newFocusedElement); | 96 HTMLFormControlElementWithState::dispatchBlurEvent(newFocusedElement); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void HTMLTextFormControlElement::defaultEventHandler(Event* event) | 99 void HTMLTextFormControlElement::defaultEventHandler(Event* event) |
| 100 { | 100 { |
| 101 if (event->type() == EventTypeNames::webkitEditableContentChanged && rendere
r() && renderer()->isTextControl()) { | 101 if (event->type() == EventTypeNames::webkitEditableContentChanged && layoutO
bject() && layoutObject()->isTextControl()) { |
| 102 m_lastChangeWasUserEdit = true; | 102 m_lastChangeWasUserEdit = true; |
| 103 subtreeHasChanged(); | 103 subtreeHasChanged(); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 HTMLFormControlElementWithState::defaultEventHandler(event); | 107 HTMLFormControlElementWithState::defaultEventHandler(event); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void HTMLTextFormControlElement::forwardEvent(Event* event) | 110 void HTMLTextFormControlElement::forwardEvent(Event* event) |
| 111 { | 111 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 142 return attributeValue.string().find(isNotLineBreak) == kNotFound; | 142 return attributeValue.string().find(isNotLineBreak) == kNotFound; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool HTMLTextFormControlElement::placeholderShouldBeVisible() const | 145 bool HTMLTextFormControlElement::placeholderShouldBeVisible() const |
| 146 { | 146 { |
| 147 return supportsPlaceholder() | 147 return supportsPlaceholder() |
| 148 && isEmptyValue() | 148 && isEmptyValue() |
| 149 && isEmptySuggestedValue() | 149 && isEmptySuggestedValue() |
| 150 && !isPlaceholderEmpty() | 150 && !isPlaceholderEmpty() |
| 151 && (document().focusedElement() != this || (LayoutTheme::theme().shouldS
howPlaceholderWhenFocused())) | 151 && (document().focusedElement() != this || (LayoutTheme::theme().shouldS
howPlaceholderWhenFocused())) |
| 152 && (!renderer() || renderer()->style()->visibility() == VISIBLE); | 152 && (!layoutObject() || layoutObject()->style()->visibility() == VISIBLE)
; |
| 153 } | 153 } |
| 154 | 154 |
| 155 HTMLElement* HTMLTextFormControlElement::placeholderElement() const | 155 HTMLElement* HTMLTextFormControlElement::placeholderElement() const |
| 156 { | 156 { |
| 157 return toHTMLElement(closedShadowRoot()->getElementById(ShadowElementNames::
placeholder())); | 157 return toHTMLElement(closedShadowRoot()->getElementById(ShadowElementNames::
placeholder())); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderVal
ueChanged) | 160 void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderVal
ueChanged) |
| 161 { | 161 { |
| 162 if (!supportsPlaceholder()) | 162 if (!supportsPlaceholder()) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 end = std::min(end, textLength); | 229 end = std::min(end, textLength); |
| 230 | 230 |
| 231 if (start < end) | 231 if (start < end) |
| 232 text.replace(start, end - start, replacement); | 232 text.replace(start, end - start, replacement); |
| 233 else | 233 else |
| 234 text.insert(replacement, start); | 234 text.insert(replacement, start); |
| 235 | 235 |
| 236 setInnerEditorValue(text); | 236 setInnerEditorValue(text); |
| 237 | 237 |
| 238 // FIXME: What should happen to the value (as in value()) if there's no rend
erer? | 238 // FIXME: What should happen to the value (as in value()) if there's no rend
erer? |
| 239 if (!renderer()) | 239 if (!layoutObject()) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 subtreeHasChanged(); | 242 subtreeHasChanged(); |
| 243 | 243 |
| 244 if (equalIgnoringCase(selectionMode, "select")) { | 244 if (equalIgnoringCase(selectionMode, "select")) { |
| 245 newSelectionStart = start; | 245 newSelectionStart = start; |
| 246 newSelectionEnd = start + replacementLength; | 246 newSelectionEnd = start + replacementLength; |
| 247 } else if (equalIgnoringCase(selectionMode, "start")) | 247 } else if (equalIgnoringCase(selectionMode, "start")) |
| 248 newSelectionStart = newSelectionEnd = start; | 248 newSelectionStart = newSelectionEnd = start; |
| 249 else if (equalIgnoringCase(selectionMode, "end")) | 249 else if (equalIgnoringCase(selectionMode, "end")) |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 containerNode = node; | 502 containerNode = node; |
| 503 offsetInContainer = offset; | 503 offsetInContainer = offset; |
| 504 } else { | 504 } else { |
| 505 containerNode = node->parentNode(); | 505 containerNode = node->parentNode(); |
| 506 offsetInContainer = node->nodeIndex() + offset; | 506 offsetInContainer = node->nodeIndex() + offset; |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 | 509 |
| 510 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const | 510 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const |
| 511 { | 511 { |
| 512 if (!renderer() || !isTextFormControl()) | 512 if (!layoutObject() || !isTextFormControl()) |
| 513 return nullptr; | 513 return nullptr; |
| 514 | 514 |
| 515 int start = m_cachedSelectionStart; | 515 int start = m_cachedSelectionStart; |
| 516 int end = m_cachedSelectionEnd; | 516 int end = m_cachedSelectionEnd; |
| 517 | 517 |
| 518 ASSERT(start <= end); | 518 ASSERT(start <= end); |
| 519 HTMLElement* innerText = innerEditorElement(); | 519 HTMLElement* innerText = innerEditorElement(); |
| 520 if (!innerText) | 520 if (!innerText) |
| 521 return nullptr; | 521 return nullptr; |
| 522 | 522 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 548 return Range::create(document(), startNode, start, endNode, end); | 548 return Range::create(document(), startNode, start, endNode, end); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void HTMLTextFormControlElement::restoreCachedSelection() | 551 void HTMLTextFormControlElement::restoreCachedSelection() |
| 552 { | 552 { |
| 553 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele
ctionDirection, NotDispatchSelectEvent); | 553 setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd, m_cachedSele
ctionDirection, NotDispatchSelectEvent); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) | 556 void HTMLTextFormControlElement::selectionChanged(bool userTriggered) |
| 557 { | 557 { |
| 558 if (!renderer() || !isTextFormControl()) | 558 if (!layoutObject() || !isTextFormControl()) |
| 559 return; | 559 return; |
| 560 | 560 |
| 561 // selectionStart() or selectionEnd() will return cached selection when this
node doesn't have focus | 561 // selectionStart() or selectionEnd() will return cached selection when this
node doesn't have focus |
| 562 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); | 562 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); |
| 563 | 563 |
| 564 if (LocalFrame* frame = document().frame()) { | 564 if (LocalFrame* frame = document().frame()) { |
| 565 if (frame->selection().isRange() && userTriggered) | 565 if (frame->selection().isRange() && userTriggered) |
| 566 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 566 dispatchEvent(Event::createBubble(EventTypeNames::select)); |
| 567 } | 567 } |
| 568 } | 568 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 591 } | 591 } |
| 592 | 592 |
| 593 void HTMLTextFormControlElement::setInnerEditorValue(const String& value) | 593 void HTMLTextFormControlElement::setInnerEditorValue(const String& value) |
| 594 { | 594 { |
| 595 ASSERT(!hasOpenShadowRoot()); | 595 ASSERT(!hasOpenShadowRoot()); |
| 596 if (!isTextFormControl() || hasOpenShadowRoot()) | 596 if (!isTextFormControl() || hasOpenShadowRoot()) |
| 597 return; | 597 return; |
| 598 | 598 |
| 599 bool textIsChanged = value != innerEditorValue(); | 599 bool textIsChanged = value != innerEditorValue(); |
| 600 if (textIsChanged || !innerEditorElement()->hasChildren()) { | 600 if (textIsChanged || !innerEditorElement()->hasChildren()) { |
| 601 if (textIsChanged && renderer()) { | 601 if (textIsChanged && layoutObject()) { |
| 602 if (AXObjectCache* cache = document().existingAXObjectCache()) | 602 if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 603 cache->handleTextFormControlChanged(this); | 603 cache->handleTextFormControlChanged(this); |
| 604 } | 604 } |
| 605 innerEditorElement()->setInnerText(value, ASSERT_NO_EXCEPTION); | 605 innerEditorElement()->setInnerText(value, ASSERT_NO_EXCEPTION); |
| 606 | 606 |
| 607 if (value.endsWith('\n') || value.endsWith('\r')) | 607 if (value.endsWith('\n') || value.endsWith('\r')) |
| 608 innerEditorElement()->appendChild(HTMLBRElement::create(document()))
; | 608 innerEditorElement()->appendChild(HTMLBRElement::create(document()))
; |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 } | 653 } |
| 654 | 654 |
| 655 String HTMLTextFormControlElement::valueWithHardLineBreaks() const | 655 String HTMLTextFormControlElement::valueWithHardLineBreaks() const |
| 656 { | 656 { |
| 657 // FIXME: It's not acceptable to ignore the HardWrap setting when there is n
o renderer. | 657 // FIXME: It's not acceptable to ignore the HardWrap setting when there is n
o renderer. |
| 658 // While we have no evidence this has ever been a practical problem, it woul
d be best to fix it some day. | 658 // While we have no evidence this has ever been a practical problem, it woul
d be best to fix it some day. |
| 659 HTMLElement* innerText = innerEditorElement(); | 659 HTMLElement* innerText = innerEditorElement(); |
| 660 if (!innerText || !isTextFormControl()) | 660 if (!innerText || !isTextFormControl()) |
| 661 return value(); | 661 return value(); |
| 662 | 662 |
| 663 LayoutBlockFlow* renderer = toLayoutBlockFlow(innerText->renderer()); | 663 LayoutBlockFlow* renderer = toLayoutBlockFlow(innerText->layoutObject()); |
| 664 if (!renderer) | 664 if (!renderer) |
| 665 return value(); | 665 return value(); |
| 666 | 666 |
| 667 Node* breakNode; | 667 Node* breakNode; |
| 668 unsigned breakOffset; | 668 unsigned breakOffset; |
| 669 RootInlineBox* line = renderer->firstRootBox(); | 669 RootInlineBox* line = renderer->firstRootBox(); |
| 670 if (!line) | 670 if (!line) |
| 671 return value(); | 671 return value(); |
| 672 | 672 |
| 673 getNextSoftBreak(line, breakNode, breakOffset); | 673 getNextSoftBreak(line, breakNode, breakOffset); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 Text* textNode = toText(node); | 970 Text* textNode = toText(node); |
| 971 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi
votPosition.offsetInContainerNode() : 0); | 971 size_t firstLineBreak = textNode->data().find('\n', isPivotNode ? pi
votPosition.offsetInContainerNode() : 0); |
| 972 if (firstLineBreak != kNotFound) | 972 if (firstLineBreak != kNotFound) |
| 973 return Position(textNode, firstLineBreak + 1); | 973 return Position(textNode, firstLineBreak + 1); |
| 974 } | 974 } |
| 975 } | 975 } |
| 976 return endOfInnerText(textFormControl); | 976 return endOfInnerText(textFormControl); |
| 977 } | 977 } |
| 978 | 978 |
| 979 } // namespace blink | 979 } // namespace blink |
| OLD | NEW |