Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 68 |
| 69 const int PopupListBox::defaultMaxHeight = 500; | 69 const int PopupListBox::defaultMaxHeight = 500; |
| 70 static const int maxVisibleRows = 20; | 70 static const int maxVisibleRows = 20; |
| 71 static const int minEndOfLinePadding = 2; | 71 static const int minEndOfLinePadding = 2; |
| 72 static const TimeStamp typeAheadTimeoutMs = 1000; | 72 static const TimeStamp typeAheadTimeoutMs = 1000; |
| 73 | 73 |
| 74 PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch, Po pupContainer* container) | 74 PopupListBox::PopupListBox(PopupMenuClient* client, bool deviceSupportsTouch, Po pupContainer* container) |
| 75 : m_deviceSupportsTouch(deviceSupportsTouch) | 75 : m_deviceSupportsTouch(deviceSupportsTouch) |
| 76 , m_originalIndex(0) | 76 , m_originalIndex(0) |
| 77 , m_selectedIndex(0) | 77 , m_selectedIndex(0) |
| 78 , m_acceptedIndexOnAbandon(-1) | |
| 79 , m_visibleRows(0) | 78 , m_visibleRows(0) |
| 80 , m_baseWidth(0) | 79 , m_baseWidth(0) |
| 81 , m_maxHeight(defaultMaxHeight) | 80 , m_maxHeight(defaultMaxHeight) |
| 82 , m_popupClient(client) | 81 , m_popupClient(client) |
| 83 , m_repeatingChar(0) | 82 , m_repeatingChar(0) |
| 84 , m_lastCharTime(0) | 83 , m_lastCharTime(0) |
| 85 , m_maxWindowWidth(std::numeric_limits<int>::max()) | 84 , m_maxWindowWidth(std::numeric_limits<int>::max()) |
| 86 , m_container(container) | 85 , m_container(container) |
| 87 { | 86 { |
| 88 } | 87 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 typeAheadFind(event); | 246 typeAheadFind(event); |
| 248 break; | 247 break; |
| 249 } | 248 } |
| 250 | 249 |
| 251 if (event.altKey() && (event.keyIdentifier() == "Down" || event.keyIdentifie r() == "Up")) { | 250 if (event.altKey() && (event.keyIdentifier() == "Down" || event.keyIdentifie r() == "Up")) { |
| 252 hidePopup(); | 251 hidePopup(); |
| 253 return true; | 252 return true; |
| 254 } | 253 } |
| 255 | 254 |
| 256 if (m_originalIndex != m_selectedIndex) { | 255 if (m_originalIndex != m_selectedIndex) { |
| 257 // Keyboard events should update the selection immediately (but we don't | |
| 258 // want to fire the onchange event until the popup is closed, to match | |
| 259 // IE). We change the original index so we revert to that when the | |
| 260 // popup is closed. | |
| 261 m_acceptedIndexOnAbandon = m_selectedIndex; | |
| 262 | |
| 263 setOriginalIndex(m_selectedIndex); | 256 setOriginalIndex(m_selectedIndex); |
|
Xianzhu
2015/03/18 16:46:22
Can we have a better name for the method? The curr
keishi
2015/03/30 22:20:52
Seemed to be barely used so I removed m_originalIn
| |
| 264 m_popupClient->setTextFromItem(m_selectedIndex); | 257 m_popupClient->setProvisionallySelectedListIndex(m_selectedIndex); |
| 265 } | 258 } |
| 266 if (event.windowsVirtualKeyCode() == VKEY_TAB) { | 259 if (event.windowsVirtualKeyCode() == VKEY_TAB) { |
| 267 // TAB is a special case as it should select the current item if any and | 260 // TAB is a special case as it should select the current item if any and |
| 268 // advance focus. | 261 // advance focus. |
| 269 if (m_selectedIndex >= 0) { | 262 if (m_selectedIndex >= 0) { |
| 270 acceptIndex(m_selectedIndex); // May delete us. | 263 acceptIndex(m_selectedIndex); // May delete us. |
| 271 // Return false so the TAB key event is propagated to the page. | 264 // Return false so the TAB key event is propagated to the page. |
| 272 return false; | 265 return false; |
| 273 } | 266 } |
| 274 // Call abandon() so we honor m_acceptedIndexOnAbandon if set. | |
| 275 abandon(); | 267 abandon(); |
| 276 // Return false so the TAB key event is propagated to the page. | 268 // Return false so the TAB key event is propagated to the page. |
| 277 return false; | 269 return false; |
| 278 } | 270 } |
| 279 | 271 |
| 280 return true; | 272 return true; |
| 281 } | 273 } |
| 282 | 274 |
| 283 HostWindow* PopupListBox::hostWindow() const | 275 HostWindow* PopupListBox::hostWindow() const |
| 284 { | 276 { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 return itemFont; | 490 return itemFont; |
| 499 } | 491 } |
| 500 | 492 |
| 501 void PopupListBox::abandon() | 493 void PopupListBox::abandon() |
| 502 { | 494 { |
| 503 RefPtrWillBeRawPtr<PopupListBox> protect(this); | 495 RefPtrWillBeRawPtr<PopupListBox> protect(this); |
| 504 | 496 |
| 505 m_selectedIndex = m_originalIndex; | 497 m_selectedIndex = m_originalIndex; |
| 506 | 498 |
| 507 hidePopup(); | 499 hidePopup(); |
| 508 | |
| 509 if (m_acceptedIndexOnAbandon >= 0) { | |
| 510 if (m_popupClient) | |
| 511 m_popupClient->valueChanged(m_acceptedIndexOnAbandon); | |
| 512 m_acceptedIndexOnAbandon = -1; | |
| 513 } | |
| 514 } | 500 } |
| 515 | 501 |
| 516 int PopupListBox::pointToRowIndex(const IntPoint& point) | 502 int PopupListBox::pointToRowIndex(const IntPoint& point) |
| 517 { | 503 { |
| 518 int y = scrollY() + point.y(); | 504 int y = scrollY() + point.y(); |
| 519 | 505 |
| 520 // FIXME: binary search if perf matters. | 506 // FIXME: binary search if perf matters. |
| 521 for (int i = 0; i < numItems(); ++i) { | 507 for (int i = 0; i < numItems(); ++i) { |
| 522 if (y < m_items[i]->yOffset) | 508 if (y < m_items[i]->yOffset) |
| 523 return i-1; | 509 return i-1; |
| 524 } | 510 } |
| 525 | 511 |
| 526 // Last item? | 512 // Last item? |
| 527 if (y < contentsSize().height()) | 513 if (y < contentsSize().height()) |
| 528 return m_items.size()-1; | 514 return m_items.size()-1; |
| 529 | 515 |
| 530 return -1; | 516 return -1; |
| 531 } | 517 } |
| 532 | 518 |
| 533 bool PopupListBox::acceptIndex(int index) | 519 bool PopupListBox::acceptIndex(int index) |
| 534 { | 520 { |
| 535 // Clear m_acceptedIndexOnAbandon once user accepts the selected index. | |
| 536 if (m_acceptedIndexOnAbandon >= 0) | |
| 537 m_acceptedIndexOnAbandon = -1; | |
| 538 | |
| 539 if (index >= numItems()) | 521 if (index >= numItems()) |
| 540 return false; | 522 return false; |
| 541 | 523 |
| 542 if (index < 0) { | 524 if (index < 0) { |
| 543 if (m_popupClient) { | 525 if (m_popupClient) { |
| 544 // Enter pressed with no selection, just close the popup. | 526 // Enter pressed with no selection, just close the popup. |
| 545 hidePopup(); | 527 hidePopup(); |
| 546 } | 528 } |
| 547 return false; | 529 return false; |
| 548 } | 530 } |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 maximumOffset.clampNegativeToZero(); | 1033 maximumOffset.clampNegativeToZero(); |
| 1052 return maximumOffset; | 1034 return maximumOffset; |
| 1053 } | 1035 } |
| 1054 | 1036 |
| 1055 IntPoint PopupListBox::minimumScrollPosition() const | 1037 IntPoint PopupListBox::minimumScrollPosition() const |
| 1056 { | 1038 { |
| 1057 return IntPoint(-scrollOrigin().x(), -scrollOrigin().y()); | 1039 return IntPoint(-scrollOrigin().x(), -scrollOrigin().y()); |
| 1058 } | 1040 } |
| 1059 | 1041 |
| 1060 } // namespace blink | 1042 } // namespace blink |
| OLD | NEW |