Skip to content

增加Selection相关接口 #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions wke/wke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,36 @@ bool wkeGoForward(wkeWebView webView)
return webView->goForward();
}

bool wkeHasSelection(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
return webView->hasSelection();
}

const utf8* wkeGetSelectedText(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
return webView->selectedText();
}

const wchar_t* wkeGetSelectedTextW(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
return webView->selectedTextW();
}

const utf8* wkeGetSelectedSource(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
return webView->selectedSource();
}

const wchar_t* wkeGetSelectedSourceW(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
return webView->selectedSourceW();
}

void wkeEditorSelectAll(wkeWebView webView)
{
wke::checkThreadCallIsValid(__FUNCTION__);
Expand Down
12 changes: 12 additions & 0 deletions wke/wke.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ WKE_API bool wkeGoBack(wkeWebView webView);
WKE_API bool wkeCanGoForward(wkeWebView webView);
WKE_API bool wkeGoForward(wkeWebView webView);

WKE_API bool wkeHasSelection(wkeWebView webView);
WKE_API const wchar_t* wkeGetSelectedTextW(wkeWebView webView);
WKE_API const utf8* wkeGetSelectedText(wkeWebView webView);
WKE_API const wchar_t* wkeGetSelectedSourceW(wkeWebView webView);
WKE_API const utf8* wkeGetSelectedSource(wkeWebView webView);

WKE_API void wkeEditorSelectAll(wkeWebView webView);
WKE_API void wkeEditorUnSelect(wkeWebView webView);
WKE_API void wkeEditorCopy(wkeWebView webView);
Expand Down Expand Up @@ -877,6 +883,12 @@ class IWebView {
virtual bool canGoForward() const = 0;
virtual bool goForward() = 0;

virtual bool hasSelection() const = 0;
virtual const wchar_t* selectedTextW() = 0;
virtual const utf8* selectedText() = 0;
virtual const wchar_t* selectedSourceW() = 0;
virtual const utf8* selectedSource() = 0;

virtual void editorSelectAll() = 0;
virtual void editorUnSelect() = 0;
virtual void editorCopy() = 0;
Expand Down
43 changes: 37 additions & 6 deletions wke/wkeWebView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (defined ENABLE_WKE) && (ENABLE_WKE == 1)
#if (defined ENABLE_WKE) && (ENABLE_WKE == 1)

#define BUILDING_wke

Expand Down Expand Up @@ -40,6 +40,8 @@ CWebView::CWebView()
, m_cookie("", 0)
, m_name("miniblink", 0)
, m_url("", 0)
, m_selectedText("", 0)
, m_selectedSource("", 0)
, m_isCokieEnabled(true)
, m_isCreatedDevTools(false)
{
Expand Down Expand Up @@ -221,7 +223,7 @@ void CWebView::_loadURL(const utf8* inUrl, bool isFile)
if (!trimPath(inUrl, isFile, &inUrlBuf))
return;

//cexer �������String::fromUTF8��ʾ����ڶ�������������String::String���inUrl����latin1������
//cexer 必须调用String::fromUTF8显示构造第二个参数,否则String::String会把inUrl当作latin1处理。
blink::KURL url(blink::ParsedURLString, &inUrlBuf[0]);
if (!url.isValid())
url.setProtocol("http:");
Expand Down Expand Up @@ -583,6 +585,35 @@ bool CWebView::goForward()
return true;
}

bool CWebView::hasSelection() const
{
return m_webPage->mainFrame()->hasSelection();
}

const wchar_t* CWebView::selectedTextW()
{
m_selectedText = (const WTF::String&) m_webPage->mainFrame()->selectionAsText();
return m_selectedText.stringW();
}

const utf8* CWebView::selectedText()
{
m_selectedText = (const WTF::String&) m_webPage->mainFrame()->selectionAsText();
return m_selectedText.string();
}

const wchar_t* CWebView::selectedSourceW()
{
m_selectedSource = (const WTF::String&) m_webPage->mainFrame()->selectionAsMarkup();
return m_selectedSource.stringW();
}

const utf8* CWebView::selectedSource()
{
m_selectedSource = (const WTF::String&) m_webPage->mainFrame()->selectionAsMarkup();
return m_selectedSource.string();
}

void CWebView::editorSelectAll()
{
m_webPage->mainFrame()->executeCommand("SelectAll");
Expand Down Expand Up @@ -893,22 +924,22 @@ static jsValue runJsImpl(blink::WebFrame* mainFrame, String* codeString, bool is
return v8ValueToJsValue(context, result);
}

jsValue CWebView::runJS(const wchar_t* script)
jsValue CWebView::runJS(const wchar_t* script, bool isInClosure)
{
if (!script)
return jsUndefined();

String codeString(script);
return runJsImpl(m_webPage->mainFrame(), &codeString, true);
return runJsImpl(m_webPage->mainFrame(), &codeString, isInClosure);
}

jsValue CWebView::runJS(const utf8* script)
jsValue CWebView::runJS(const utf8* script, bool isInClosure)
{
if (!script)
return jsUndefined();

String codeString = String::fromUTF8(script);
return runJsImpl(m_webPage->mainFrame(), &codeString, true);
return runJsImpl(m_webPage->mainFrame(), &codeString, isInClosure);
}

jsValue CWebView::runJsInFrame(wkeWebFrameHandle frameId, const utf8* script, bool isInClosure)
Expand Down
14 changes: 11 additions & 3 deletions wke/wkeWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ class CWebView : public IWebView {
bool goBack() override;
bool canGoForward() const override;
bool goForward() override;


bool hasSelection() const override;
const wchar_t* selectedTextW() override;
const utf8* selectedText() override;
const wchar_t* selectedSourceW() override;
const utf8* selectedSource() override;

void editorSelectAll() override;
void editorUnSelect() override;
void editorCopy() override;
Expand Down Expand Up @@ -222,8 +228,8 @@ class CWebView : public IWebView {
static int64_t wkeWebFrameHandleToFrameId(content::WebPage* page, wkeWebFrameHandle frameId);
static wkeWebFrameHandle frameIdTowkeWebFrameHandle(content::WebPage* page, int64_t frameId);

jsValue runJS(const wchar_t* script) override;
jsValue runJS(const utf8* script) override;
jsValue runJS(const wchar_t* script, bool isInClosure = true) override;
jsValue runJS(const utf8* script, bool isInClosure = true) override;
jsValue runJsInFrame(wkeWebFrameHandle frameId, const utf8* script, bool isInClosure);
jsExecState globalExec() override;
jsExecState globalExecByFrame(wkeWebFrameHandle frameId);
Expand Down Expand Up @@ -338,6 +344,8 @@ class CWebView : public IWebView {
wke::CString m_title;
wke::CString m_cookie;
wke::CString m_name;
wke::CString m_selectedText;
wke::CString m_selectedSource;
bool m_transparent;
bool m_isCokieEnabled;

Expand Down
16 changes: 14 additions & 2 deletions wke/wkedefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ class IWebView {
virtual bool canGoForward() const = 0;
virtual bool goForward() = 0;

virtual bool hasSelection() const = 0;
virtual const wchar_t* selectedTextW() = 0;
virtual const utf8* selectedText() = 0;
virtual const wchar_t* selectedSourceW() = 0;
virtual const utf8* selectedSource() = 0;

virtual void editorSelectAll() = 0;
virtual void editorUnSelect() = 0;
virtual void editorCopy() = 0;
Expand Down Expand Up @@ -638,8 +644,8 @@ class IWebView {

virtual wkeRect getCaret() = 0;

virtual jsValue runJS(const utf8* script) = 0;
virtual jsValue runJS(const wchar_t* script) = 0;
virtual jsValue runJS(const utf8* script, bool isInClosure = true) = 0;
virtual jsValue runJS(const wchar_t* script, bool isInClosure = true) = 0;
virtual jsExecState globalExec() = 0;

virtual void sleep() = 0; //moveOffscreen
Expand Down Expand Up @@ -913,6 +919,12 @@ class IWebView {
ITERATOR1(bool, wkeCanGoForward, wkeWebView webView, "") \
ITERATOR1(bool, wkeGoForward, wkeWebView webView, "") \
\
ITERATOR1(bool, wkeHasSelection, wkeWebView webView, "") \
ITERATOR1(const wchar_t*, wkeGetSelectedTextW, wkeWebView webView, "") \
ITERATOR1(const utf8*, wkeGetSelectedText, wkeWebView webView, "") \
ITERATOR1(const wchar_t*, wkeGetSelectedSourceW, wkeWebView webView, "") \
ITERATOR1(const utf8*, wkeGetSelectedSource, wkeWebView webView, "") \
\
ITERATOR1(void, wkeEditorSelectAll, wkeWebView webView, "") \
ITERATOR1(void, wkeEditorUnSelect, wkeWebView webView, "") \
ITERATOR1(void, wkeEditorCopy, wkeWebView webView, "") \
Expand Down