| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2007 Google Inc. All Rights Reserved. | 2 * Copyright 2007 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * ***** BEGIN LICENSE BLOCK ***** | 6 * ***** BEGIN LICENSE BLOCK ***** |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 suggestions_.clear(); | 257 suggestions_.clear(); |
| 258 for (std::vector<std::wstring>::const_iterator iter = suggestions.begin(); | 258 for (std::vector<std::wstring>::const_iterator iter = suggestions.begin(); |
| 259 iter != suggestions.end(); ++iter) { | 259 iter != suggestions.end(); ++iter) { |
| 260 suggestions_.push_back(webkit_glue::StdWStringToString(*iter)); | 260 suggestions_.push_back(webkit_glue::StdWStringToString(*iter)); |
| 261 } | 261 } |
| 262 // Try to preserve selection if possible. | 262 // Try to preserve selection if possible. |
| 263 if (selected_index_ >= static_cast<int>(suggestions.size())) | 263 if (selected_index_ >= static_cast<int>(suggestions.size())) |
| 264 selected_index_ = -1; | 264 selected_index_ = -1; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void RemoveItemAtIndex(int index) { |
| 268 DCHECK(index >= 0 && index < static_cast<int>(suggestions_.size())); |
| 269 suggestions_.erase(suggestions_.begin() + index); |
| 270 } |
| 271 |
| 267 WebCore::HTMLInputElement* text_field() const { | 272 WebCore::HTMLInputElement* text_field() const { |
| 268 return text_field_.get(); | 273 return text_field_.get(); |
| 269 } | 274 } |
| 270 | 275 |
| 271 WebCore::RenderStyle* GetTextFieldStyle() const { | 276 WebCore::RenderStyle* GetTextFieldStyle() const { |
| 272 WebCore::RenderStyle* style = text_field_->computedStyle(); | 277 WebCore::RenderStyle* style = text_field_->computedStyle(); |
| 273 if (!style) { | 278 if (!style) { |
| 274 // It seems we can only have an NULL style in a TextField if the node is | 279 // It seems we can only have an NULL style in a TextField if the node is |
| 275 // dettached, in which case we the popup shoud not be showing. | 280 // dettached, in which case we the popup shoud not be showing. |
| 276 NOTREACHED() << "Please report this in http://crbug.com/7708 and include " | 281 NOTREACHED() << "Please report this in http://crbug.com/7708 and include " |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 } | 536 } |
| 532 | 537 |
| 533 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { | 538 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { |
| 534 if (!autocomplete_popup_showing_ || | 539 if (!autocomplete_popup_showing_ || |
| 535 // Home and End should be left to the text field to process. | 540 // Home and End should be left to the text field to process. |
| 536 event.windows_key_code == base::VKEY_HOME || | 541 event.windows_key_code == base::VKEY_HOME || |
| 537 event.windows_key_code == base::VKEY_END) { | 542 event.windows_key_code == base::VKEY_END) { |
| 538 return false; | 543 return false; |
| 539 } | 544 } |
| 540 | 545 |
| 546 // Pressing delete triggers the removal of the selected suggestion from the |
| 547 // DB. |
| 548 if (event.windows_key_code == base::VKEY_DELETE && |
| 549 autocomplete_popup_->selectedIndex() != -1) { |
| 550 Node* node = GetFocusedNode(); |
| 551 if (!node || (node->nodeType() != WebCore::Node::ELEMENT_NODE)) { |
| 552 NOTREACHED(); |
| 553 return false; |
| 554 } |
| 555 WebCore::Element* element = static_cast<WebCore::Element*>(node); |
| 556 if (!element->hasLocalName(WebCore::HTMLNames::inputTag)) { |
| 557 NOTREACHED(); |
| 558 return false; |
| 559 } |
| 560 |
| 561 int selected_index = autocomplete_popup_->selectedIndex(); |
| 562 WebCore::HTMLInputElement* input_element = |
| 563 static_cast<WebCore::HTMLInputElement*>(element); |
| 564 std::wstring name = webkit_glue::StringToStdWString(input_element->name()); |
| 565 std::wstring value = webkit_glue::StringToStdWString( |
| 566 autocomplete_popup_client_->itemText(selected_index )); |
| 567 delegate()->RemoveStoredAutofillEntry(name, value); |
| 568 // Update the entries in the currently showing popup to reflect the |
| 569 // deletion. |
| 570 autocomplete_popup_client_->RemoveItemAtIndex(selected_index); |
| 571 RefreshAutofillPopup(); |
| 572 return false; |
| 573 } |
| 574 |
| 541 if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code)) | 575 if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code)) |
| 542 return false; | 576 return false; |
| 543 | 577 |
| 544 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { | 578 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { |
| 545 #if defined(OS_WIN) | 579 #if defined(OS_WIN) |
| 546 // We need to ignore the next CHAR event after this otherwise pressing | 580 // We need to ignore the next CHAR event after this otherwise pressing |
| 547 // enter when selecting an item in the menu will go to the page. | 581 // enter when selecting an item in the menu will go to the page. |
| 548 if (WebInputEvent::RAW_KEY_DOWN == event.type) | 582 if (WebInputEvent::RAW_KEY_DOWN == event.type) |
| 549 suppress_next_keypress_event_ = true; | 583 suppress_next_keypress_event_ = true; |
| 550 #endif | 584 #endif |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 suggestions, | 1614 suggestions, |
| 1581 default_suggestion_index); | 1615 default_suggestion_index); |
| 1582 if (!autocomplete_popup_.get()) { | 1616 if (!autocomplete_popup_.get()) { |
| 1583 autocomplete_popup_ = | 1617 autocomplete_popup_ = |
| 1584 WebCore::PopupContainer::create(autocomplete_popup_client_.get(), | 1618 WebCore::PopupContainer::create(autocomplete_popup_client_.get(), |
| 1585 kAutocompletePopupSettings); | 1619 kAutocompletePopupSettings); |
| 1586 } | 1620 } |
| 1587 | 1621 |
| 1588 if (autocomplete_popup_showing_) { | 1622 if (autocomplete_popup_showing_) { |
| 1589 autocomplete_popup_client_->SetSuggestions(suggestions); | 1623 autocomplete_popup_client_->SetSuggestions(suggestions); |
| 1590 IntRect old_bounds = autocomplete_popup_->boundsRect(); | 1624 RefreshAutofillPopup(); |
| 1591 autocomplete_popup_->refresh(); | |
| 1592 IntRect new_bounds = autocomplete_popup_->boundsRect(); | |
| 1593 // Let's resize the backing window if necessary. | |
| 1594 if (old_bounds != new_bounds) { | |
| 1595 WebWidgetImpl* web_widget = | |
| 1596 static_cast<WebWidgetImpl*>(autocomplete_popup_->client()); | |
| 1597 web_widget->delegate()->SetWindowRect( | |
| 1598 web_widget, webkit_glue::FromIntRect(new_bounds)); | |
| 1599 } | |
| 1600 } else { | 1625 } else { |
| 1601 autocomplete_popup_->show(focused_node->getRect(), | 1626 autocomplete_popup_->show(focused_node->getRect(), |
| 1602 focused_node->ownerDocument()->view(), 0); | 1627 focused_node->ownerDocument()->view(), 0); |
| 1603 autocomplete_popup_showing_ = true; | 1628 autocomplete_popup_showing_ = true; |
| 1604 } | 1629 } |
| 1605 } | 1630 } |
| 1606 } | 1631 } |
| 1607 | 1632 |
| 1608 void WebViewImpl::DidCommitLoad(bool* is_new_navigation) { | 1633 void WebViewImpl::DidCommitLoad(bool* is_new_navigation) { |
| 1609 if (is_new_navigation) | 1634 if (is_new_navigation) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 if (autocomplete_popup_) { | 1714 if (autocomplete_popup_) { |
| 1690 autocomplete_popup_->hidePopup(); | 1715 autocomplete_popup_->hidePopup(); |
| 1691 autocomplete_popup_showing_ = false; | 1716 autocomplete_popup_showing_ = false; |
| 1692 } | 1717 } |
| 1693 } | 1718 } |
| 1694 | 1719 |
| 1695 void WebViewImpl::HideAutofillPopup() { | 1720 void WebViewImpl::HideAutofillPopup() { |
| 1696 HideAutoCompletePopup(); | 1721 HideAutoCompletePopup(); |
| 1697 } | 1722 } |
| 1698 | 1723 |
| 1724 void WebViewImpl::RefreshAutofillPopup() { |
| 1725 DCHECK(autocomplete_popup_showing_); |
| 1726 IntRect old_bounds = autocomplete_popup_->boundsRect(); |
| 1727 autocomplete_popup_->refresh(); |
| 1728 IntRect new_bounds = autocomplete_popup_->boundsRect(); |
| 1729 // Let's resize the backing window if necessary. |
| 1730 if (old_bounds != new_bounds) { |
| 1731 WebWidgetImpl* web_widget = |
| 1732 static_cast<WebWidgetImpl*>(autocomplete_popup_->client()); |
| 1733 web_widget->delegate()->SetWindowRect( |
| 1734 web_widget, webkit_glue::FromIntRect(new_bounds)); |
| 1735 } |
| 1736 } |
| 1737 |
| 1699 Node* WebViewImpl::GetFocusedNode() { | 1738 Node* WebViewImpl::GetFocusedNode() { |
| 1700 Frame* frame = page_->focusController()->focusedFrame(); | 1739 Frame* frame = page_->focusController()->focusedFrame(); |
| 1701 if (!frame) | 1740 if (!frame) |
| 1702 return NULL; | 1741 return NULL; |
| 1703 | 1742 |
| 1704 Document* document = frame->document(); | 1743 Document* document = frame->document(); |
| 1705 if (!document) | 1744 if (!document) |
| 1706 return NULL; | 1745 return NULL; |
| 1707 | 1746 |
| 1708 return document->focusedNode(); | 1747 return document->focusedNode(); |
| 1709 } | 1748 } |
| OLD | NEW |