OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
4 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
10 * | 10 * |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "core/events/MouseEvent.h" | 44 #include "core/events/MouseEvent.h" |
45 #include "core/frame/FrameHost.h" | 45 #include "core/frame/FrameHost.h" |
46 #include "core/frame/FrameView.h" | 46 #include "core/frame/FrameView.h" |
47 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
48 #include "core/html/FormDataList.h" | 48 #include "core/html/FormDataList.h" |
49 #include "core/html/HTMLFormElement.h" | 49 #include "core/html/HTMLFormElement.h" |
50 #include "core/html/HTMLOptGroupElement.h" | 50 #include "core/html/HTMLOptGroupElement.h" |
51 #include "core/html/HTMLOptionElement.h" | 51 #include "core/html/HTMLOptionElement.h" |
52 #include "core/html/forms/FormController.h" | 52 #include "core/html/forms/FormController.h" |
53 #include "core/input/EventHandler.h" | 53 #include "core/input/EventHandler.h" |
54 #include "core/inspector/ConsoleMessage.h" | |
54 #include "core/layout/HitTestRequest.h" | 55 #include "core/layout/HitTestRequest.h" |
55 #include "core/layout/HitTestResult.h" | 56 #include "core/layout/HitTestResult.h" |
56 #include "core/layout/LayoutListBox.h" | 57 #include "core/layout/LayoutListBox.h" |
57 #include "core/layout/LayoutMenuList.h" | 58 #include "core/layout/LayoutMenuList.h" |
58 #include "core/layout/LayoutText.h" | 59 #include "core/layout/LayoutText.h" |
59 #include "core/layout/LayoutTheme.h" | 60 #include "core/layout/LayoutTheme.h" |
60 #include "core/layout/LayoutView.h" | 61 #include "core/layout/LayoutView.h" |
61 #include "core/page/AutoscrollController.h" | 62 #include "core/page/AutoscrollController.h" |
62 #include "core/page/ChromeClient.h" | 63 #include "core/page/ChromeClient.h" |
63 #include "core/page/Page.h" | 64 #include "core/page/Page.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 return options()->namedItem(name); | 461 return options()->namedItem(name); |
461 } | 462 } |
462 | 463 |
463 HTMLOptionElement* HTMLSelectElement::item(unsigned index) | 464 HTMLOptionElement* HTMLSelectElement::item(unsigned index) |
464 { | 465 { |
465 return options()->item(index); | 466 return options()->item(index); |
466 } | 467 } |
467 | 468 |
468 void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc eptionState& exceptionState) | 469 void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc eptionState& exceptionState) |
469 { | 470 { |
470 if (index > maxSelectItems - 1) | 471 if (index >= length() && index >= maxSelectItems) { |
davve
2015/08/20 07:40:43
I like that you added the comparison to current le
tkent
2015/08/20 08:05:47
Yeah, I'll add this to the description.
Shrinking
| |
471 index = maxSelectItems - 1; | 472 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War ningMessageLevel, |
473 String::format("A request to update an option at index=%u is ignored . The maximum length is %u.", index, maxSelectItems))); | |
keishi
2015/08/20 07:39:46
nit: Other messages seemed to be like "Failed to b
tkent
2015/08/20 08:05:47
will do.
| |
474 return; | |
475 } | |
472 int diff = index - length(); | 476 int diff = index - length(); |
473 HTMLOptionElementOrHTMLOptGroupElement element; | 477 HTMLOptionElementOrHTMLOptGroupElement element; |
474 element.setHTMLOptionElement(option); | 478 element.setHTMLOptionElement(option); |
475 HTMLElementOrLong before; | 479 HTMLElementOrLong before; |
476 // Out of array bounds? First insert empty dummies. | 480 // Out of array bounds? First insert empty dummies. |
477 if (diff > 0) { | 481 if (diff > 0) { |
478 setLength(index, exceptionState); | 482 setLength(index, exceptionState); |
479 // Replace an existing entry? | 483 // Replace an existing entry? |
480 } else if (diff < 0) { | 484 } else if (diff < 0) { |
481 before.setHTMLElement(options()->item(index + 1)); | 485 before.setHTMLElement(options()->item(index + 1)); |
482 remove(index); | 486 remove(index); |
483 } | 487 } |
484 // Finally add the new element. | 488 // Finally add the new element. |
485 if (!exceptionState.hadException()) { | 489 if (!exceptionState.hadException()) { |
486 add(element, before, exceptionState); | 490 add(element, before, exceptionState); |
487 if (diff >= 0 && option->selected()) | 491 if (diff >= 0 && option->selected()) |
488 optionSelectionStateChanged(option, true); | 492 optionSelectionStateChanged(option, true); |
489 } | 493 } |
490 } | 494 } |
491 | 495 |
492 void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionStat e) | 496 void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionStat e) |
493 { | 497 { |
494 if (newLen > maxSelectItems) | 498 if (newLen > length() && newLen > maxSelectItems) { |
499 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War ningMessageLevel, | |
500 String::format("A request to update the option length to %u is ignor ed. The maximum length is %u.", newLen, maxSelectItems))); | |
495 return; | 501 return; |
502 } | |
496 int diff = length() - newLen; | 503 int diff = length() - newLen; |
497 | 504 |
498 if (diff < 0) { // Add dummy elements. | 505 if (diff < 0) { // Add dummy elements. |
499 do { | 506 do { |
500 appendChild(document().createElement(optionTag, false), exceptionSta te); | 507 appendChild(document().createElement(optionTag, false), exceptionSta te); |
501 if (exceptionState.hadException()) | 508 if (exceptionState.hadException()) |
502 break; | 509 break; |
503 } while (++diff); | 510 } while (++diff); |
504 } else { | 511 } else { |
505 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listIte ms(); | 512 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listIte ms(); |
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1938 void HTMLSelectElement::detach(const AttachContext& context) | 1945 void HTMLSelectElement::detach(const AttachContext& context) |
1939 { | 1946 { |
1940 HTMLFormControlElementWithState::detach(context); | 1947 HTMLFormControlElementWithState::detach(context); |
1941 if (m_popup) | 1948 if (m_popup) |
1942 m_popup->disconnectClient(); | 1949 m_popup->disconnectClient(); |
1943 m_popupIsVisible = false; | 1950 m_popupIsVisible = false; |
1944 m_popup = nullptr; | 1951 m_popup = nullptr; |
1945 } | 1952 } |
1946 | 1953 |
1947 } // namespace blink | 1954 } // namespace blink |
OLD | NEW |