Esempio n. 1
0
bool Page::findString(const String& target, TextCaseSensitivity caseSensitivity, FindDirection direction, bool shouldWrap)
{
    if (target.isEmpty() || !mainFrame())
        return false;

    Frame* frame = focusController()->focusedOrMainFrame();
    Frame* startFrame = frame;
    do {
        if (frame->findString(target, direction == FindDirectionForward, caseSensitivity == TextCaseSensitive, false, true)) {
            if (frame != startFrame)
                startFrame->selection()->clear();
            focusController()->setFocusedFrame(frame);
            return true;
        }
        frame = incrementFrame(frame, direction == FindDirectionForward, shouldWrap);
    } while (frame && frame != startFrame);

    // Search contents of startFrame, on the other side of the selection that we did earlier.
    // We cheat a bit and just research with wrap on
    if (shouldWrap && !startFrame->selection()->isNone()) {
        bool found = startFrame->findString(target, direction == FindDirectionForward, caseSensitivity == TextCaseSensitive, true, true);
        focusController()->setFocusedFrame(frame);
        return found;
    }

    return false;
}
Esempio n. 2
0
bool Page::findString(const String& target, FindOptions options)
{
    if (target.isEmpty() || !mainFrame())
        return false;

    bool shouldWrap = options & WrapAround;
    Frame* frame = focusController()->focusedOrMainFrame();
    Frame* startFrame = frame;
    do {
        if (frame->editor().findString(target, (options & ~WrapAround) | StartInSelection)) {
            if (frame != startFrame)
                startFrame->selection()->clear();
            focusController()->setFocusedFrame(frame);
            return true;
        }
        frame = incrementFrame(frame, !(options & Backwards), shouldWrap);
    } while (frame && frame != startFrame);

    // Search contents of startFrame, on the other side of the selection that we did earlier.
    // We cheat a bit and just research with wrap on
    if (shouldWrap && !startFrame->selection()->isNone()) {
        bool found = startFrame->editor().findString(target, options | WrapAround | StartInSelection);
        focusController()->setFocusedFrame(frame);
        return found;
    }

    return false;
}
Esempio n. 3
0
TEST_F(FocusControllerTest, SetInitialFocus) {
  document().body()->setInnerHTML("<input><textarea>");
  Element* input = toElement(document().body()->firstChild());
  // Set sequential focus navigation point before the initial focus.
  input->focus();
  input->blur();
  focusController().setInitialFocus(WebFocusTypeForward);
  EXPECT_EQ(input, document().focusedElement())
      << "We should ignore sequential focus navigation starting point in "
         "setInitialFocus().";
}
Esempio n. 4
0
TEST_F(FocusControllerTest, DoNotCrash2) {
  document().body()->setInnerHTML(
      "<p id='target' tabindex='0'></p>This test is for crbug.com/609012<div "
      "id='host'></div>");
  // <p>
  Element* target = toElement(document().body()->firstChild());
  // "This test is for crbug.com/609012"
  Node* text = target->nextSibling();
  // <div> with shadow root
  Element* host = toElement(text->nextSibling());
  ShadowRootInit init;
  init.setMode("open");
  host->attachShadow(ScriptState::forMainWorld(document().frame()), init,
                     ASSERT_NO_EXCEPTION);

  // Set sequential focus navigation point at text node.
  document().setSequentialFocusNavigationStartingPoint(text);

  focusController().advanceFocus(WebFocusTypeBackward);
  EXPECT_EQ(target, document().focusedElement())
      << "This should not hit assertion and finish properly.";
}
Esempio n. 5
0
const Selection& Page::selection() const
{
    return focusController()->focusedOrMainFrame()->selection()->selection();
}