* Implemented a mechanism to ask the BWebPage about it's editing capabilities.
This needs to be asynchronous, as always. BrowserWindow asks when menus are opened, but the result arrives so fast, that the user never sees invalid items. The Cut/Copy/Paste items are now always enabled according to what's currently really possible. * Enable and disable the Back/Forward History menu items along with the buttons. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@436 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
62c697303a
commit
9b70fc27d2
@@ -239,8 +239,10 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
||||
mainMenu->AddItem(menu);
|
||||
|
||||
fHistoryMenu = new BMenu("History");
|
||||
fHistoryMenu->AddItem(new BMenuItem("Back", new BMessage(GO_BACK), B_LEFT_ARROW));
|
||||
fHistoryMenu->AddItem(new BMenuItem("Forward", new BMessage(GO_FORWARD), B_RIGHT_ARROW));
|
||||
fHistoryMenu->AddItem(fBackMenuItem = new BMenuItem("Back",
|
||||
new BMessage(GO_BACK), B_LEFT_ARROW));
|
||||
fHistoryMenu->AddItem(fForwardMenuItem = new BMenuItem("Forward",
|
||||
new BMessage(GO_FORWARD), B_RIGHT_ARROW));
|
||||
fHistoryMenu->AddSeparatorItem();
|
||||
fHistoryMenuFixedItemCount = fHistoryMenu->CountItems();
|
||||
mainMenu->AddItem(fHistoryMenu);
|
||||
@@ -594,6 +596,29 @@ BrowserWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case B_EDITING_CAPABILITIES_RESULT:
|
||||
{
|
||||
BWebView* webView;
|
||||
if (message->FindPointer("view",
|
||||
reinterpret_cast<void**>(&webView)) != B_OK
|
||||
|| webView != CurrentWebView()) {
|
||||
break;
|
||||
}
|
||||
bool canCut;
|
||||
bool canCopy;
|
||||
bool canPaste;
|
||||
if (message->FindBool("can cut", &canCut) != B_OK)
|
||||
canCut = false;
|
||||
if (message->FindBool("can copy", &canCopy) != B_OK)
|
||||
canCopy = false;
|
||||
if (message->FindBool("can paste", &canPaste) != B_OK)
|
||||
canPaste = false;
|
||||
fCutMenuItem->SetEnabled(canCut);
|
||||
fCopyMenuItem->SetEnabled(canCopy);
|
||||
fPasteMenuItem->SetEnabled(canPaste);
|
||||
break;
|
||||
}
|
||||
|
||||
case SHOW_DOWNLOAD_WINDOW:
|
||||
case SHOW_SETTINGS_WINDOW:
|
||||
message->AddUInt32("workspaces", Workspaces());
|
||||
@@ -683,6 +708,19 @@ BrowserWindow::MenusBeginning()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BrowserWindow::MenusEnded()
|
||||
{
|
||||
// Reenabled the clipboard items, since we don't update them when
|
||||
// the capabilities really change, but only when the menu is opened.
|
||||
// The shortcuts need to work when the capabilities change without
|
||||
// the Edit menu being opened meanwhile.
|
||||
fCutMenuItem->SetEnabled(true);
|
||||
fCopyMenuItem->SetEnabled(true);
|
||||
fPasteMenuItem->SetEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BrowserWindow::CreateNewTab(const BString& url, bool select, BWebView* webView)
|
||||
{
|
||||
@@ -957,12 +995,12 @@ BrowserWindow::NavigationCapabilitiesChanged(bool canGoBackward,
|
||||
if (view != CurrentWebView())
|
||||
return;
|
||||
|
||||
if (fBackButton)
|
||||
fBackButton->SetEnabled(canGoBackward);
|
||||
if (fForwardButton)
|
||||
fForwardButton->SetEnabled(canGoForward);
|
||||
if (fStopButton)
|
||||
fStopButton->SetEnabled(canStop);
|
||||
fBackButton->SetEnabled(canGoBackward);
|
||||
fForwardButton->SetEnabled(canGoForward);
|
||||
fStopButton->SetEnabled(canStop);
|
||||
|
||||
fBackMenuItem->SetEnabled(canGoBackward);
|
||||
fForwardMenuItem->SetEnabled(canGoForward);
|
||||
}
|
||||
|
||||
|
||||
@@ -1405,9 +1443,16 @@ BrowserWindow::_UpdateClipboardItems()
|
||||
fCutMenuItem->SetEnabled(hasSelection);
|
||||
fCopyMenuItem->SetEnabled(hasSelection);
|
||||
fPasteMenuItem->SetEnabled(canPaste);
|
||||
} else if (CurrentFocus() != CurrentWebView()) {
|
||||
} else if (CurrentWebView() != NULL) {
|
||||
// Trigger update of the clipboard items, even if the
|
||||
// BWebView doesn't have focus, we'll dispatch these message
|
||||
// there anyway. This works so fast that the user can never see
|
||||
// the wrong enabled state when the menu opens until the result
|
||||
// message arrives.
|
||||
fCutMenuItem->SetEnabled(false);
|
||||
fCopyMenuItem->SetEnabled(false);
|
||||
fPasteMenuItem->SetEnabled(false);
|
||||
|
||||
CurrentWebView()->WebPage()->SendEditingCapabilities();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual bool QuitRequested();
|
||||
virtual void MenusBeginning();
|
||||
virtual void MenusEnded();
|
||||
|
||||
void CreateNewTab(const BString& url, bool select,
|
||||
BWebView* webView = 0);
|
||||
@@ -156,6 +157,8 @@ private:
|
||||
BMenuItem* fFindPreviousMenuItem;
|
||||
BMenuItem* fFindNextMenuItem;
|
||||
BMenuItem* fZoomTextOnlyMenuItem;
|
||||
BMenuItem* fBackMenuItem;
|
||||
BMenuItem* fForwardMenuItem;
|
||||
|
||||
IconButton* fBackButton;
|
||||
IconButton* fForwardButton;
|
||||
|
||||
Reference in New Issue
Block a user