This commit is contained in:
ccarlen%netscape.com 2000-11-14 03:45:53 +00:00
Родитель 2c4646c800
Коммит 3dfc6e2393
2 изменённых файлов: 435 добавлений и 328 удалений

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
@ -17,7 +17,7 @@
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <conrad@ingress.com>
* Conrad Carlen <ccarlen@netscape.com>
*/
#ifndef __CBrowserShell__
@ -35,6 +35,7 @@
#include "nsIDocShellTreeOwner.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWebProgressListener.h"
#include "nsIClipboardCommands.h"
#include <UModalDialogs.h>
#include <LStream.h>
@ -86,28 +87,28 @@ CBrowserShell::CBrowserShell(LStream* inStream) :
CBrowserShell::~CBrowserShell()
{
delete mFinder;
delete mFinder;
// nsCOMPtr destructors, do your thing
// nsCOMPtr destructors, do your thing
}
NS_IMETHODIMP CBrowserShell::CommonConstruct()
{
nsresult rv;
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(baseWin, NS_ERROR_FAILURE);
mWebBrowserAsBaseWin = baseWin;
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
mWebBrowserAsWebNav = webNav;
nsresult rv;
return NS_OK;
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(baseWin, NS_ERROR_FAILURE);
mWebBrowserAsBaseWin = baseWin;
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
mWebBrowserAsWebNav = webNav;
return NS_OK;
}
@ -131,27 +132,27 @@ void CBrowserShell::FinishCreateSelf()
CalcPortFrameRect(portFrame);
nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top);
mWebBrowserAsBaseWin->InitWindow(aWidget->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height);
mWebBrowserAsBaseWin->Create();
mWebBrowserAsBaseWin->InitWindow(aWidget->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height);
mWebBrowserAsBaseWin->Create();
AdjustFrame();
AdjustFrame();
StartRepeating();
StartListening();
}
void CBrowserShell::ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh)
void CBrowserShell::ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh)
{
LView::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
AdjustFrame();
}
void CBrowserShell::MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh)
void CBrowserShell::MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh)
{
LView::MoveBy(inHorizDelta, inVertDelta, inRefresh);
AdjustFrame();
@ -160,15 +161,15 @@ void CBrowserShell::MoveBy(SInt32 inHorizDelta,
void CBrowserShell::ShowSelf()
{
mWebBrowserAsBaseWin->SetVisibility(PR_TRUE);
mWebBrowserAsBaseWin->SetVisibility(PR_TRUE);
}
void CBrowserShell::DrawSelf()
{
EventRecord osEvent;
osEvent.what = updateEvt;
mMessageSink.DispatchOSEvent(osEvent, GetMacPort());
EventRecord osEvent;
osEvent.what = updateEvt;
mMessageSink.DispatchOSEvent(osEvent, GetMacPort());
}
@ -184,21 +185,21 @@ void CBrowserShell::ClickSelf(const SMouseDownEvent &inMouseDown)
void CBrowserShell::EventMouseUp(const EventRecord &inMacEvent)
{
FocusDraw();
mMessageSink.DispatchOSEvent((EventRecord&)inMacEvent, GetMacPort());
FocusDraw();
mMessageSink.DispatchOSEvent((EventRecord&)inMacEvent, GetMacPort());
}
void CBrowserShell::AdjustCursorSelf(Point /* inPortPt */,
const EventRecord& inMacEvent)
{
static Point lastWhere = {0, 0};
static Point lastWhere = {0, 0};
if ((*(long*)&lastWhere != *(long*)&inMacEvent.where))
{
HandleMouseMoved(inMacEvent);
lastWhere = inMacEvent.where;
}
if ((*(long*)&lastWhere != *(long*)&inMacEvent.where))
{
HandleMouseMoved(inMacEvent);
lastWhere = inMacEvent.where;
}
}
@ -222,6 +223,91 @@ Boolean CBrowserShell::HandleKeyPress(const EventRecord &inKeyEvent)
return keyHandled;
}
Boolean CBrowserShell::ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioParam)
{
Boolean cmdHandled = true;
nsresult rv;
nsCOMPtr<nsIClipboardCommands> clipCmd;
switch (inCommand)
{
case cmd_Cut:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv))
clipCmd->CutSelection();
break;
case cmd_Copy:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv))
clipCmd->CopySelection();
break;
case cmd_Paste:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv))
clipCmd->PasteSelection();
break;
case cmd_SelectAll:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv))
clipCmd->SelectAll();
break;
default:
cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
void CBrowserShell::FindCommandStatus(PP_PowerPlant::CommandT inCommand,
Boolean &outEnabled, Boolean &outUsesMark,
PP_PowerPlant::Char16 &outMark, Str255 outName)
{
nsresult rv;
nsCOMPtr<nsIClipboardCommands> clipCmd;
PRBool canDo;
switch (inCommand)
{
case cmd_Cut:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv)) {
rv = clipCmd->CanCutSelection(&canDo);
outEnabled = NS_SUCCEEDED(rv) && canDo;
}
break;
case cmd_Copy:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv)) {
rv = clipCmd->CanCopySelection(&canDo);
outEnabled = NS_SUCCEEDED(rv) && canDo;
}
break;
case cmd_Paste:
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv)) {
rv = clipCmd->CanPasteSelection(&canDo);
outEnabled = NS_SUCCEEDED(rv) && canDo;
}
break;
case cmd_SelectAll:
outEnabled = PR_TRUE;
break;
default:
LCommander::FindCommandStatus(inCommand, outEnabled,
outUsesMark, outMark, outName);
break;
}
}
//*****************************************************************************
@ -230,20 +316,19 @@ Boolean CBrowserShell::HandleKeyPress(const EventRecord &inKeyEvent)
void CBrowserShell::SpendTime(const EventRecord& inMacEvent)
{
switch (inMacEvent.what)
{
case osEvt:
{
// The MacMessageSink will not set the cursor if we are in the background - which is right.
// We have to feed it suspendResumeMessages for it to know
switch (inMacEvent.what)
{
case osEvt:
{
// The MacMessageSink will not set the cursor if we are in the background - which is right.
// We have to feed it suspendResumeMessages for it to know
unsigned char eventType = ((inMacEvent.message >> 24) & 0x00ff);
if (eventType == suspendResumeMessage)
mMessageSink.DispatchOSEvent(const_cast<EventRecord&>(inMacEvent), GetMacPort());
}
break;
}
unsigned char eventType = ((inMacEvent.message >> 24) & 0x00ff);
if (eventType == suspendResumeMessage)
mMessageSink.DispatchOSEvent(const_cast<EventRecord&>(inMacEvent), GetMacPort());
}
break;
}
}
//*****************************************************************************
@ -268,62 +353,62 @@ void CBrowserShell::ListenToMessage(MessageT inMessage,
NS_IMETHODIMP CBrowserShell::SetTopLevelWindow(nsIWebBrowserChrome * aTopLevelWindow)
{
mWebBrowser->SetContainerWindow(aTopLevelWindow);
/*
In case we needed to do something with the underlying docshell...
mWebBrowser->SetContainerWindow(aTopLevelWindow);
nsCOMPtr<nsIDocShell> ourDocShell(do_GetInterface(mWebBrowser));
NS_ENSURE_TRUE(ourDocShell, NS_ERROR_FAILURE);
*/
return NS_OK;
/*
In case we needed to do something with the underlying docshell...
nsCOMPtr<nsIDocShell> ourDocShell(do_GetInterface(mWebBrowser));
NS_ENSURE_TRUE(ourDocShell, NS_ERROR_FAILURE);
*/
return NS_OK;
}
NS_METHOD CBrowserShell::GetWebBrowser(nsIWebBrowser** aBrowser)
{
NS_ENSURE_ARG_POINTER(aBrowser);
NS_ENSURE_ARG_POINTER(aBrowser);
*aBrowser = mWebBrowser;
NS_IF_ADDREF(*aBrowser);
return NS_OK;
*aBrowser = mWebBrowser;
NS_IF_ADDREF(*aBrowser);
return NS_OK;
}
NS_METHOD CBrowserShell::SetWebBrowser(nsIWebBrowser* aBrowser)
{
NS_ENSURE_ARG(aBrowser);
NS_ENSURE_ARG(aBrowser);
FocusDraw();
CBrowserWindow *ourWindow = dynamic_cast<CBrowserWindow*>(LWindow::FetchWindowObject(GetMacPort()));
NS_ENSURE_TRUE(ourWindow, NS_ERROR_FAILURE);
nsCOMPtr<nsIWidget> aWidget;
ourWindow->GetWidget(getter_AddRefs(aWidget));
NS_ENSURE_TRUE(aWidget, NS_ERROR_FAILURE);
mWebBrowser = aBrowser;
FocusDraw();
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(baseWin, NS_ERROR_FAILURE);
mWebBrowserAsBaseWin = baseWin;
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
mWebBrowserAsWebNav = webNav;
CBrowserWindow *ourWindow = dynamic_cast<CBrowserWindow*>(LWindow::FetchWindowObject(GetMacPort()));
NS_ENSURE_TRUE(ourWindow, NS_ERROR_FAILURE);
Rect portFrame;
CalcPortFrameRect(portFrame);
nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top);
mWebBrowserAsBaseWin->InitWindow(aWidget->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height);
mWebBrowserAsBaseWin->Create();
AdjustFrame();
nsCOMPtr<nsIWidget> aWidget;
ourWindow->GetWidget(getter_AddRefs(aWidget));
NS_ENSURE_TRUE(aWidget, NS_ERROR_FAILURE);
return NS_OK;
mWebBrowser = aBrowser;
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(baseWin, NS_ERROR_FAILURE);
mWebBrowserAsBaseWin = baseWin;
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
mWebBrowserAsWebNav = webNav;
Rect portFrame;
CalcPortFrameRect(portFrame);
nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top);
mWebBrowserAsBaseWin->InitWindow(aWidget->GetNativeData(NS_NATIVE_WIDGET), nsnull, r.x, r.y, r.width, r.height);
mWebBrowserAsBaseWin->Create();
AdjustFrame();
return NS_OK;
}
@ -333,49 +418,49 @@ NS_METHOD CBrowserShell::SetWebBrowser(nsIWebBrowser* aBrowser)
Boolean CBrowserShell::CanGoBack()
{
PRBool canDo;
nsresult rv;
rv = mWebBrowserAsWebNav->GetCanGoBack(&canDo);
return (NS_SUCCEEDED(rv) && canDo);
PRBool canDo;
nsresult rv;
rv = mWebBrowserAsWebNav->GetCanGoBack(&canDo);
return (NS_SUCCEEDED(rv) && canDo);
}
Boolean CBrowserShell::CanGoForward()
{
PRBool canDo;
nsresult rv;
rv = mWebBrowserAsWebNav->GetCanGoForward(&canDo);
return (NS_SUCCEEDED(rv) && canDo);
PRBool canDo;
nsresult rv;
rv = mWebBrowserAsWebNav->GetCanGoForward(&canDo);
return (NS_SUCCEEDED(rv) && canDo);
}
Boolean CBrowserShell::IsLoading()
{
return false;
return false;
}
void CBrowserShell::Back()
{
if (CanGoBack())
mWebBrowserAsWebNav->GoBack();
else
::SysBeep(5);
if (CanGoBack())
mWebBrowserAsWebNav->GoBack();
else
::SysBeep(5);
}
void CBrowserShell::Forward()
{
if (CanGoForward())
mWebBrowserAsWebNav->GoForward();
else
::SysBeep(5);
if (CanGoForward())
mWebBrowserAsWebNav->GoForward();
else
::SysBeep(5);
}
void CBrowserShell::Stop()
{
mWebBrowserAsWebNav->Stop();
mWebBrowserAsWebNav->Stop();
}
//*****************************************************************************
@ -391,9 +476,9 @@ void CBrowserShell::LoadURL(Ptr urlText, SInt32 urlTextLen)
void CBrowserShell::LoadURL(const nsString& urlText)
{
nsresult rv = mWebBrowserAsWebNav->LoadURI(urlText.GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);
if (NS_FAILED(rv))
Throw_(NS_ERROR_GET_CODE(rv));
nsresult rv = mWebBrowserAsWebNav->LoadURI(urlText.GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);
if (NS_FAILED(rv))
Throw_(NS_ERROR_GET_CODE(rv));
}
@ -403,36 +488,36 @@ void CBrowserShell::LoadURL(const nsString& urlText)
Boolean CBrowserShell::Find()
{
// Make sure we have a finder
nsresult rv = EnsureFinder();
if (NS_FAILED(rv)) // Throw an exception??
// Make sure we have a finder
nsresult rv = EnsureFinder();
if (NS_FAILED(rv)) // Throw an exception??
return FALSE;
// Get the current find params from it
nsString searchString;
PRBool caseSensitive;
PRBool wrapSearch;
PRBool seachBackwards;
PRBool entireWord;
mFinder->GetLastSearchString(searchString);
mFinder->GetLastCaseSensitive(caseSensitive);
mFinder->GetLastWrapSearch(wrapSearch);
mFinder->GetLastSearchBackwards(seachBackwards);
mFinder->GetLastEntireWord(entireWord);
Boolean result = FALSE;
if (GetFindParams(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord))
{
PRBool didFind;
mFinder->Find(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord, didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
}
return result;
// Get the current find params from it
nsString searchString;
PRBool caseSensitive;
PRBool wrapSearch;
PRBool seachBackwards;
PRBool entireWord;
mFinder->GetLastSearchString(searchString);
mFinder->GetLastCaseSensitive(caseSensitive);
mFinder->GetLastWrapSearch(wrapSearch);
mFinder->GetLastSearchBackwards(seachBackwards);
mFinder->GetLastEntireWord(entireWord);
Boolean result = FALSE;
if (GetFindParams(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord))
{
PRBool didFind;
mFinder->Find(searchString, caseSensitive, seachBackwards, wrapSearch, entireWord, didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
}
return result;
}
@ -442,97 +527,97 @@ Boolean CBrowserShell::Find(const nsString& searchString,
Boolean wrapSearch,
Boolean entireWord)
{
// Make sure we have a finder
nsresult rv = EnsureFinder();
if (NS_FAILED(rv)) // Throw an exception??
return FALSE;
// Make sure we have a finder
nsresult rv = EnsureFinder();
if (NS_FAILED(rv)) // Throw an exception??
return FALSE;
Boolean result;
PRBool didFind;
rv = mFinder->Find(searchString, caseSensitive, searchBackwards, wrapSearch, entireWord, didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
Boolean result;
PRBool didFind;
return result;
rv = mFinder->Find(searchString, caseSensitive, searchBackwards, wrapSearch, entireWord, didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
return result;
}
Boolean CBrowserShell::CanFindNext()
{
if (!mFinder)
return FALSE;
if (!mFinder)
return FALSE;
nsresult rv;
PRBool canDo;
rv = mFinder->CanFindNext(canDo);
return (NS_SUCCEEDED(rv) && canDo);
nsresult rv;
PRBool canDo;
rv = mFinder->CanFindNext(canDo);
return (NS_SUCCEEDED(rv) && canDo);
}
Boolean CBrowserShell::FindNext()
{
if (!mFinder)
{
SignalStringLiteral_("This should not be called until Find is called");
return FALSE;
}
Boolean result;
PRBool didFind;
nsresult rv = mFinder->FindNext(didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
if (!mFinder)
{
SignalStringLiteral_("This should not be called until Find is called");
return FALSE;
}
return result;
Boolean result;
PRBool didFind;
nsresult rv = mFinder->FindNext(didFind);
result = (NS_SUCCEEDED(rv) && didFind);
if (!result)
::SysBeep(1);
return result;
}
void CBrowserShell::HandleMouseMoved(const EventRecord& inMacEvent)
{
if (IsActive())
{
FocusDraw();
mMessageSink.DispatchOSEvent(const_cast<EventRecord&>(inMacEvent), GetMacPort());
}
if (IsActive())
{
FocusDraw();
mMessageSink.DispatchOSEvent(const_cast<EventRecord&>(inMacEvent), GetMacPort());
}
}
void CBrowserShell::AdjustFrame()
{
FocusDraw();
Rect portFrame;
CalcPortFrameRect(portFrame);
nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top);
FocusDraw();
Rect portFrame;
CalcPortFrameRect(portFrame);
nsRect r(portFrame.left, portFrame.top, portFrame.right - portFrame.left, portFrame.bottom - portFrame.top);
mWebBrowserAsBaseWin->SetPositionAndSize(r.x, r.y, r.width, r.height, PR_TRUE);
mWebBrowserAsBaseWin->SetPositionAndSize(r.x, r.y, r.width, r.height, PR_TRUE);
}
NS_METHOD CBrowserShell::EnsureFinder()
{
nsCOMPtr<nsIDocShell> ourDocShell(do_GetInterface(mWebBrowser));
if (mFinder)
{
// For now, we have to clear the context each time.
// The finder should be a nsIDocumentLoaderObserver and then
// it could clear itself when the contents of our docshell changed.
nsCOMPtr<nsIDocShell> ourDocShell(do_GetInterface(mWebBrowser));
mFinder->SetContext(nsnull);
mFinder->SetContext(ourDocShell);
return NS_OK;
}
if (mFinder)
{
// For now, we have to clear the context each time.
// The finder should be a nsIDocumentLoaderObserver and then
// it could clear itself when the contents of our docshell changed.
mFinder->SetContext(nsnull);
mFinder->SetContext(ourDocShell);
return NS_OK;
}
mFinder = new CFindComponent;
NS_ENSURE_TRUE(mFinder, NS_ERROR_OUT_OF_MEMORY);
mFinder->SetContext(ourDocShell);
return NS_OK;
mFinder = new CFindComponent;
NS_ENSURE_TRUE(mFinder, NS_ERROR_OUT_OF_MEMORY);
mFinder->SetContext(ourDocShell);
return NS_OK;
}
@ -542,75 +627,74 @@ Boolean CBrowserShell::GetFindParams(nsString& searchText,
PRBool& wrapSearch,
PRBool& entireWord)
{
enum
{
kSearchTextEdit = FOUR_CHAR_CODE('Text'),
kCaseSensitiveCheck = FOUR_CHAR_CODE('Case'),
kWrapAroundCheck = FOUR_CHAR_CODE('Wrap'),
kSearchBackwardsCheck = FOUR_CHAR_CODE('Back'),
kEntireWordCheck = FOUR_CHAR_CODE('Entr')
};
Boolean result;
try
{
// Create stack-based object for handling the dialog box
StDialogHandler theHandler(dlog_FindDialog, this);
LWindow *theDialog = theHandler.GetDialog();
Str255 aStr;
enum
{
kSearchTextEdit = FOUR_CHAR_CODE('Text'),
kCaseSensitiveCheck = FOUR_CHAR_CODE('Case'),
kWrapAroundCheck = FOUR_CHAR_CODE('Wrap'),
kSearchBackwardsCheck = FOUR_CHAR_CODE('Back'),
kEntireWordCheck = FOUR_CHAR_CODE('Entr')
};
// Set initial text for string in dialog box
Boolean result;
UMacUnicode::StringToStr255(searchText, aStr);
LEditText *editField = dynamic_cast<LEditText*>(theDialog->FindPaneByID(kSearchTextEdit));
editField->SetDescriptor(aStr);
theDialog->SetLatentSub(editField);
LCheckBox *caseSensCheck, *entireWordCheck, *wrapAroundCheck, *backwardsCheck;
caseSensCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kCaseSensitiveCheck));
ThrowIfNot_(caseSensCheck);
caseSensCheck->SetValue(caseSensitive ? 1 : 0);
entireWordCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kEntireWordCheck));
ThrowIfNot_(entireWordCheck);
entireWordCheck->SetValue(entireWord ? 1 : 0);
wrapAroundCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kWrapAroundCheck));
ThrowIfNot_(wrapAroundCheck);
wrapAroundCheck->SetValue(wrapSearch ? 1 : 0);
backwardsCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kSearchBackwardsCheck));
ThrowIfNot_(backwardsCheck);
backwardsCheck->SetValue(searchBackwards ? 1 : 0);
theDialog->Show();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_Cancel)
{
result = FALSE;
break;
}
else if (hitMessage == msg_OK)
{
editField->GetDescriptor(aStr);
UMacUnicode::Str255ToString(aStr, searchText);
caseSensitive = caseSensCheck->GetValue() ? TRUE : FALSE;
entireWord = entireWordCheck->GetValue() ? TRUE : FALSE;
wrapSearch = wrapAroundCheck->GetValue() ? TRUE : FALSE;
searchBackwards = backwardsCheck->GetValue() ? TRUE : FALSE;
result = TRUE;
break;
}
}
}
try
{
// Create stack-based object for handling the dialog box
StDialogHandler theHandler(dlog_FindDialog, this);
LWindow *theDialog = theHandler.GetDialog();
Str255 aStr;
// Set initial text for string in dialog box
UMacUnicode::StringToStr255(searchText, aStr);
LEditText *editField = dynamic_cast<LEditText*>(theDialog->FindPaneByID(kSearchTextEdit));
editField->SetDescriptor(aStr);
theDialog->SetLatentSub(editField);
LCheckBox *caseSensCheck, *entireWordCheck, *wrapAroundCheck, *backwardsCheck;
caseSensCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kCaseSensitiveCheck));
ThrowIfNot_(caseSensCheck);
caseSensCheck->SetValue(caseSensitive ? 1 : 0);
entireWordCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kEntireWordCheck));
ThrowIfNot_(entireWordCheck);
entireWordCheck->SetValue(entireWord ? 1 : 0);
wrapAroundCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kWrapAroundCheck));
ThrowIfNot_(wrapAroundCheck);
wrapAroundCheck->SetValue(wrapSearch ? 1 : 0);
backwardsCheck = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID(kSearchBackwardsCheck));
ThrowIfNot_(backwardsCheck);
backwardsCheck->SetValue(searchBackwards ? 1 : 0);
theDialog->Show();
while (true) // This is our modal dialog event loop
{
MessageT hitMessage = theHandler.DoDialog();
if (hitMessage == msg_Cancel)
{
result = FALSE;
break;
}
else if (hitMessage == msg_OK)
{
editField->GetDescriptor(aStr);
UMacUnicode::Str255ToString(aStr, searchText);
caseSensitive = caseSensCheck->GetValue() ? TRUE : FALSE;
entireWord = entireWordCheck->GetValue() ? TRUE : FALSE;
wrapSearch = wrapAroundCheck->GetValue() ? TRUE : FALSE;
searchBackwards = backwardsCheck->GetValue() ? TRUE : FALSE;
result = TRUE;
break;
}
}
}
catch (...)
{
result = FALSE;
@ -620,3 +704,18 @@ Boolean CBrowserShell::GetFindParams(nsString& searchText,
return result;
}
nsresult CBrowserShell::GetClipboardHandler(nsIClipboardCommands **aCommand)
{
NS_ENSURE_ARG_POINTER(aCommand);
nsCOMPtr<nsIDocShell> docShell(do_GetInterface(mWebBrowser));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIClipboardCommands> clipCmd(do_QueryInterface(docShell));
NS_ENSURE_TRUE(clipCmd, NS_ERROR_FAILURE);
*aCommand = clipCmd;
NS_ADDREF(*aCommand);
return NS_OK;
}

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
@ -17,7 +17,7 @@
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <conrad@ingress.com>
* Conrad Carlen <ccarlen@netscape.com>
*/
#ifndef __CBrowserShell__
@ -44,15 +44,16 @@
class CBrowserWindow;
class CURIContentListener;
class CFindComponent;
class nsIClipboardCommands;
//*****************************************************************************
//*** CBrowserShell
//*****************************************************************************
class CBrowserShell : public LView,
public LCommander,
public LPeriodical,
public LListener
public LCommander,
public LPeriodical,
public LListener
{
private:
@ -63,87 +64,94 @@ public:
enum { cmd_Find = 'Find', cmd_FindNext = 'FNxt' };
CBrowserShell();
CBrowserShell(LStream* inStream);
CBrowserShell();
CBrowserShell(LStream* inStream);
virtual ~CBrowserShell();
virtual ~CBrowserShell();
// LPane
virtual void FinishCreateSelf();
virtual void ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh);
virtual void MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh);
virtual void ShowSelf();
virtual void DrawSelf();
virtual void ClickSelf(const SMouseDownEvent &inMouseDown);
virtual void EventMouseUp(const EventRecord &inMacEvent);
virtual void AdjustCursorSelf(Point inPortPt,
const EventRecord& inMacEvent);
virtual void FinishCreateSelf();
virtual void ResizeFrameBy(SInt16 inWidthDelta,
SInt16 inHeightDelta,
Boolean inRefresh);
virtual void MoveBy(SInt32 inHorizDelta,
SInt32 inVertDelta,
Boolean inRefresh);
virtual void ShowSelf();
virtual void DrawSelf();
virtual void ClickSelf(const SMouseDownEvent &inMouseDown);
virtual void EventMouseUp(const EventRecord &inMacEvent);
virtual void AdjustCursorSelf(Point inPortPt,
const EventRecord& inMacEvent);
// LCommander
virtual void DontBeTarget();
virtual Boolean HandleKeyPress(const EventRecord &inKeyEvent);
virtual void DontBeTarget();
virtual Boolean HandleKeyPress(const EventRecord &inKeyEvent);
virtual Boolean ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioParam);
virtual void FindCommandStatus(PP_PowerPlant::CommandT inCommand,
Boolean &outEnabled, Boolean &outUsesMark,
PP_PowerPlant::Char16 &outMark, Str255 outName);
// LPeriodical
virtual void SpendTime(const EventRecord& inMacEvent);
virtual void SpendTime(const EventRecord& inMacEvent);
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
// CBrowserShell
NS_METHOD SetTopLevelWindow(nsIWebBrowserChrome * aTopLevelWindow);
NS_METHOD GetWebBrowser(nsIWebBrowser** aBrowser);
NS_METHOD SetWebBrowser(nsIWebBrowser* aBrowser);
// Drops ref to current one, installs given one
NS_METHOD SetTopLevelWindow(nsIWebBrowserChrome * aTopLevelWindow);
NS_METHOD GetWebBrowser(nsIWebBrowser** aBrowser);
NS_METHOD SetWebBrowser(nsIWebBrowser* aBrowser);
// Drops ref to current one, installs given one
Boolean CanGoBack();
Boolean CanGoForward();
Boolean IsLoading();
void Back();
void Forward();
void Stop();
Boolean CanGoBack();
Boolean CanGoForward();
Boolean IsLoading();
void Back();
void Forward();
void Stop();
void LoadURL(Ptr urlText, SInt32 urlTextLen);
void LoadURL(const nsString& urlText);
void LoadURL(Ptr urlText, SInt32 urlTextLen);
void LoadURL(const nsString& urlText);
// Puts up a find dialog and does the find operation
Boolean Find();
Boolean Find();
// Does the find operation with the given params - no UI
Boolean Find(const nsString& searchStr,
Boolean caseSensitive,
Boolean searchBackward,
Boolean wrapSearch,
Boolean wholeWordOnly);
Boolean CanFindNext();
Boolean FindNext();
Boolean Find(const nsString& searchStr,
Boolean caseSensitive,
Boolean searchBackward,
Boolean wrapSearch,
Boolean wholeWordOnly);
Boolean CanFindNext();
Boolean FindNext();
protected:
NS_METHOD CommonConstruct();
NS_METHOD CommonConstruct();
void HandleMouseMoved(const EventRecord& inMacEvent);
void AdjustFrame();
NS_METHOD EnsureFinder();
virtual Boolean GetFindParams(nsString& searchText,
PRBool& caseSensitive,
PRBool& searchBackwards,
PRBool& wrapSearch,
PRBool& entireWord);
void HandleMouseMoved(const EventRecord& inMacEvent);
void AdjustFrame();
NS_METHOD EnsureFinder();
virtual Boolean GetFindParams(nsString& searchText,
PRBool& caseSensitive,
PRBool& searchBackwards,
PRBool& wrapSearch,
PRBool& entireWord);
nsresult GetClipboardHandler(nsIClipboardCommands **aCommand);
protected:
static nsMacMessageSink mMessageSink;
LStr255 mInitURL;
LStr255 mInitURL;
nsCOMPtr<nsIWebBrowser> mWebBrowser; // The thing we actually create
nsCOMPtr<nsIBaseWindow> mWebBrowserAsBaseWin; // Convenience interface to above
nsCOMPtr<nsIWebNavigation> mWebBrowserAsWebNav; // Ditto
nsCOMPtr<nsIWebBrowser> mWebBrowser; // The thing we actually create
nsCOMPtr<nsIBaseWindow> mWebBrowserAsBaseWin; // Convenience interface to above
nsCOMPtr<nsIWebNavigation> mWebBrowserAsWebNav; // Ditto
CFindComponent* mFinder;
CFindComponent* mFinder;
};