OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 UserMetricsRecordAction("SelectAll"); | 1618 UserMetricsRecordAction("SelectAll"); |
1619 } | 1619 } |
1620 | 1620 |
1621 void RenderView::OnSetInitialFocus(bool reverse) { | 1621 void RenderView::OnSetInitialFocus(bool reverse) { |
1622 if (!webview()) | 1622 if (!webview()) |
1623 return; | 1623 return; |
1624 webview()->setInitialFocus(reverse); | 1624 webview()->setInitialFocus(reverse); |
1625 } | 1625 } |
1626 | 1626 |
1627 void RenderView::OnScrollFocusedEditableNodeIntoView() { | 1627 void RenderView::OnScrollFocusedEditableNodeIntoView() { |
1628 if (!webview()) | 1628 WebNode node; |
1629 return; | 1629 if (GetFocusedNode(node)) { |
1630 WebFrame* focused_frame = webview()->focusedFrame(); | 1630 if (IsEditableNode(node)) |
1631 if (focused_frame) { | 1631 // TODO(varunjain): Change webkit API to scroll a particular node into |
1632 WebDocument doc = focused_frame->document(); | 1632 // view and use that API here instead. |
1633 if (!doc.isNull()) { | 1633 webview()->scrollFocusedNodeIntoView(); |
1634 WebNode node = doc.focusedNode(); | |
1635 if (IsEditableNode(node)) | |
1636 // TODO(varunjain): Change webkit API to scroll a particular node into | |
1637 // view and use that API here instead. | |
1638 webview()->scrollFocusedNodeIntoView(); | |
1639 } | |
1640 } | 1634 } |
1641 } | 1635 } |
1642 | 1636 |
1643 /////////////////////////////////////////////////////////////////////////////// | 1637 /////////////////////////////////////////////////////////////////////////////// |
1644 | 1638 |
1645 void RenderView::SetContentSettings(const ContentSettings& settings) { | 1639 void RenderView::SetContentSettings(const ContentSettings& settings) { |
1646 current_content_settings_ = settings; | 1640 current_content_settings_ = settings; |
1647 } | 1641 } |
1648 | 1642 |
1649 // Tell the embedding application that the URL of the active page has changed | 1643 // Tell the embedding application that the URL of the active page has changed |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 | 2393 |
2400 bool RenderView::isShowingSpellingUI() { | 2394 bool RenderView::isShowingSpellingUI() { |
2401 return spelling_panel_visible_; | 2395 return spelling_panel_visible_; |
2402 } | 2396 } |
2403 | 2397 |
2404 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { | 2398 void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
2405 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, | 2399 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
2406 word)); | 2400 word)); |
2407 } | 2401 } |
2408 | 2402 |
| 2403 void RenderView::continuousSpellCheckingEnabledStateChanged() { |
| 2404 UpdateToggleSpellCheckCommandState(); |
| 2405 } |
| 2406 |
2409 bool RenderView::runFileChooser( | 2407 bool RenderView::runFileChooser( |
2410 const WebKit::WebFileChooserParams& params, | 2408 const WebKit::WebFileChooserParams& params, |
2411 WebFileChooserCompletion* chooser_completion) { | 2409 WebFileChooserCompletion* chooser_completion) { |
2412 // Do not open the file dialog in a hidden RenderView. | 2410 // Do not open the file dialog in a hidden RenderView. |
2413 if (is_hidden()) | 2411 if (is_hidden()) |
2414 return false; | 2412 return false; |
2415 ViewHostMsg_RunFileChooser_Params ipc_params; | 2413 ViewHostMsg_RunFileChooser_Params ipc_params; |
2416 if (params.directory) | 2414 if (params.directory) |
2417 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; | 2415 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
2418 else if (params.multiSelect) | 2416 else if (params.multiSelect) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 // any existing pending sends. | 2523 // any existing pending sends. |
2526 pending_target_url_ = latest_url; | 2524 pending_target_url_ = latest_url; |
2527 target_url_status_ = TARGET_PENDING; | 2525 target_url_status_ = TARGET_PENDING; |
2528 } else { | 2526 } else { |
2529 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); | 2527 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
2530 target_url_ = latest_url; | 2528 target_url_ = latest_url; |
2531 target_url_status_ = TARGET_INFLIGHT; | 2529 target_url_status_ = TARGET_INFLIGHT; |
2532 } | 2530 } |
2533 } | 2531 } |
2534 | 2532 |
| 2533 void RenderView::UpdateToggleSpellCheckCommandState() { |
| 2534 bool is_enabled = false; |
| 2535 WebNode node; |
| 2536 if (GetFocusedNode(node)) |
| 2537 is_enabled = IsEditableNode(node); |
| 2538 |
| 2539 int checked_state = 0; |
| 2540 if (is_enabled && webview()) { |
| 2541 WebFrame* frame = webview()->focusedFrame(); |
| 2542 if (frame->isContinuousSpellCheckingEnabled()) { |
| 2543 checked_state = 1; |
| 2544 } |
| 2545 } |
| 2546 |
| 2547 Send(new ViewHostMsg_CommandStateChanged(routing_id_, |
| 2548 "ToggleSpellCheck", |
| 2549 is_enabled, |
| 2550 checked_state)); |
| 2551 } |
| 2552 |
2535 void RenderView::StartNavStateSyncTimerIfNecessary() { | 2553 void RenderView::StartNavStateSyncTimerIfNecessary() { |
2536 int delay; | 2554 int delay; |
2537 if (send_content_state_immediately_) | 2555 if (send_content_state_immediately_) |
2538 delay = 0; | 2556 delay = 0; |
2539 else if (is_hidden()) | 2557 else if (is_hidden()) |
2540 delay = kDelaySecondsForContentStateSyncHidden; | 2558 delay = kDelaySecondsForContentStateSyncHidden; |
2541 else | 2559 else |
2542 delay = kDelaySecondsForContentStateSync; | 2560 delay = kDelaySecondsForContentStateSync; |
2543 | 2561 |
2544 if (nav_state_sync_timer_.IsRunning()) { | 2562 if (nav_state_sync_timer_.IsRunning()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 void RenderView::focusedNodeChanged(const WebNode& node) { | 2619 void RenderView::focusedNodeChanged(const WebNode& node) { |
2602 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); | 2620 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
2603 | 2621 |
2604 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { | 2622 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
2605 // TODO(ctguil): Make WebKit send this notification. | 2623 // TODO(ctguil): Make WebKit send this notification. |
2606 // When focus is cleared notify accessibility that the document is focused. | 2624 // When focus is cleared notify accessibility that the document is focused. |
2607 postAccessibilityNotification( | 2625 postAccessibilityNotification( |
2608 webview()->accessibilityObject(), | 2626 webview()->accessibilityObject(), |
2609 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); | 2627 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
2610 } | 2628 } |
| 2629 |
| 2630 UpdateToggleSpellCheckCommandState(); |
2611 } | 2631 } |
2612 | 2632 |
2613 void RenderView::navigateBackForwardSoon(int offset) { | 2633 void RenderView::navigateBackForwardSoon(int offset) { |
2614 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); | 2634 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
2615 } | 2635 } |
2616 | 2636 |
2617 int RenderView::historyBackListCount() { | 2637 int RenderView::historyBackListCount() { |
2618 return history_list_offset_ < 0 ? 0 : history_list_offset_; | 2638 return history_list_offset_ < 0 ? 0 : history_list_offset_; |
2619 } | 2639 } |
2620 | 2640 |
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4565 xpath_remaining.erase(0, delim_pos + 1); | 4585 xpath_remaining.erase(0, delim_pos + 1); |
4566 } else { | 4586 } else { |
4567 xpath_remaining.swap(xpath_child); | 4587 xpath_remaining.swap(xpath_child); |
4568 } | 4588 } |
4569 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); | 4589 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
4570 } | 4590 } |
4571 | 4591 |
4572 return frame; | 4592 return frame; |
4573 } | 4593 } |
4574 | 4594 |
| 4595 bool RenderView::GetFocusedNode(WebNode& node) const { |
| 4596 if (!webview()) |
| 4597 return false; |
| 4598 WebFrame* focused_frame = webview()->focusedFrame(); |
| 4599 if (focused_frame) { |
| 4600 WebDocument doc = focused_frame->document(); |
| 4601 if (!doc.isNull()) { |
| 4602 node = doc.focusedNode(); |
| 4603 return true; |
| 4604 } |
| 4605 } |
| 4606 |
| 4607 return false; |
| 4608 } |
| 4609 |
4575 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { | 4610 void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) { |
4576 // Explicitly allow empty vector to be sent to the browser. | 4611 // Explicitly allow empty vector to be sent to the browser. |
4577 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); | 4612 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions)); |
4578 } | 4613 } |
4579 | 4614 |
4580 void RenderView::EvaluateScript(const string16& frame_xpath, | 4615 void RenderView::EvaluateScript(const string16& frame_xpath, |
4581 const string16& script, | 4616 const string16& script, |
4582 int id, | 4617 int id, |
4583 bool notify_result) { | 4618 bool notify_result) { |
4584 v8::Handle<v8::Value> result; | 4619 v8::Handle<v8::Value> result; |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5766 external_popup_menu_.reset(); | 5801 external_popup_menu_.reset(); |
5767 } | 5802 } |
5768 #endif | 5803 #endif |
5769 | 5804 |
5770 void RenderView::AddErrorToRootConsole(const string16& message) { | 5805 void RenderView::AddErrorToRootConsole(const string16& message) { |
5771 if (webview() && webview()->mainFrame()) { | 5806 if (webview() && webview()->mainFrame()) { |
5772 webview()->mainFrame()->addMessageToConsole( | 5807 webview()->mainFrame()->addMessageToConsole( |
5773 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 5808 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
5774 } | 5809 } |
5775 } | 5810 } |
OLD | NEW |