14835 r=pavlov sr=sfraser alpha blending on images to denote selection.
This commit is contained in:
Родитель
6ec7dec1d6
Коммит
9b2ec88fda
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: IDL; 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
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
class imgIContainer;
|
||||
%}
|
||||
|
||||
[ptr] native imgIContainer(imgIContainer);
|
||||
|
||||
|
||||
[uuid(f6f68e3c-f078-4235-bf71-53d180c37d26)]
|
||||
interface nsISelectionImageService : nsISupports
|
||||
{
|
||||
/**
|
||||
* the current image is marked as invalid
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* retrieve the image for alpha blending
|
||||
*/
|
||||
void getImage(in short selectionValue, out imgIContainer container);
|
||||
|
||||
};
|
|
@ -33,8 +33,7 @@
|
|||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsCOMPtr.h"
|
||||
* ***** END LICENSE BLOCK ***** */#include "nsCOMPtr.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPref.h"
|
||||
|
@ -77,6 +76,9 @@
|
|||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIImageFrame.h"
|
||||
|
||||
//needed for resetting of image service color
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsISelectionImageService.h"
|
||||
|
||||
static nscolor
|
||||
MakeColorPref(const char *colstr)
|
||||
|
@ -130,6 +132,8 @@ PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* clo
|
|||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
|
||||
|
||||
|
||||
nsPresContext::nsPresContext()
|
||||
: mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
||||
|
@ -1734,6 +1738,13 @@ nsPresContext::SysColorChanged()
|
|||
mShell->GetStyleSet(getter_AddRefs(set));
|
||||
set->ClearStyleData(this, nsnull, nsnull);
|
||||
}
|
||||
nsCOMPtr<nsISelectionImageService> imageService;
|
||||
nsresult result;
|
||||
imageService = do_GetService(kSelectionImageService, &result);
|
||||
if (NS_SUCCEEDED(result) && imageService)
|
||||
{
|
||||
imageService->Reset();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1566,7 +1566,7 @@ PresShell::PresShell():
|
|||
if (! gLog)
|
||||
gLog = PR_NewLogModule("PresShell");
|
||||
#endif
|
||||
mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT;
|
||||
mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT | nsISelectionDisplay::DISPLAY_IMAGES;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(PresShell)
|
||||
|
|
|
@ -82,6 +82,7 @@ endif
|
|||
|
||||
XPIDLSRCS = \
|
||||
nsIChromeEventHandler.idl \
|
||||
nsISelectionImageService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: IDL; 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
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
class imgIContainer;
|
||||
%}
|
||||
|
||||
[ptr] native imgIContainer(imgIContainer);
|
||||
|
||||
|
||||
[uuid(f6f68e3c-f078-4235-bf71-53d180c37d26)]
|
||||
interface nsISelectionImageService : nsISupports
|
||||
{
|
||||
/**
|
||||
* the current image is marked as invalid
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* retrieve the image for alpha blending
|
||||
*/
|
||||
void getImage(in short selectionValue, out imgIContainer container);
|
||||
|
||||
};
|
|
@ -33,8 +33,7 @@
|
|||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsCOMPtr.h"
|
||||
* ***** END LICENSE BLOCK ***** */#include "nsCOMPtr.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPref.h"
|
||||
|
@ -77,6 +76,9 @@
|
|||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIImageFrame.h"
|
||||
|
||||
//needed for resetting of image service color
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsISelectionImageService.h"
|
||||
|
||||
static nscolor
|
||||
MakeColorPref(const char *colstr)
|
||||
|
@ -130,6 +132,8 @@ PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* clo
|
|||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
#include "nsContentCID.h"
|
||||
static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
|
||||
|
||||
|
||||
nsPresContext::nsPresContext()
|
||||
: mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
||||
|
@ -1734,6 +1738,13 @@ nsPresContext::SysColorChanged()
|
|||
mShell->GetStyleSet(getter_AddRefs(set));
|
||||
set->ClearStyleData(this, nsnull, nsnull);
|
||||
}
|
||||
nsCOMPtr<nsISelectionImageService> imageService;
|
||||
nsresult result;
|
||||
imageService = do_GetService(kSelectionImageService, &result);
|
||||
if (NS_SUCCEEDED(result) && imageService)
|
||||
{
|
||||
imageService->Reset();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -250,4 +250,8 @@
|
|||
#define NS_LAYOUT_HISTORY_STATE_CID \
|
||||
{ 0x5c5af390, 0x34be, 0x11d5, { 0xa0, 0x3b, 0x00, 0x10, 0xa4, 0xef, 0x48, 0xc9 } }
|
||||
|
||||
// {9d1001b1-e59a-456b-99dc-cc3f1283236e}
|
||||
#define NS_SELECTIONIMAGESERVICE_CID \
|
||||
{ 0x9d1001b1, 0xe59a, 0x456b, { 0x99, 0xdc, 0xcc, 0x3f, 0x12, 0x83, 0x23, 0x6e } }
|
||||
|
||||
#endif /* nsLayoutCID_h__ */
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "nsColorNames.h" // to addref/release table
|
||||
#include "nsCSSFrameConstructor.h"
|
||||
#include "nsSpaceManager.h"
|
||||
#include "nsISelectionImageService.h"
|
||||
|
||||
#ifdef INCLUDE_XUL
|
||||
#include "nsXULAtoms.h"
|
||||
|
@ -188,6 +189,7 @@ extern nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
|
|||
extern nsresult NS_CreateCSSFrameConstructor(nsICSSFrameConstructor** aResult);
|
||||
extern nsresult NS_NewLayoutHistoryState(nsILayoutHistoryState** aResult);
|
||||
extern nsresult NS_NewAutoCopyService(nsIAutoCopyService** aResult);
|
||||
extern nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult);
|
||||
|
||||
#define MAKE_CTOR(ctor_, iface_, func_) \
|
||||
static NS_IMETHODIMP \
|
||||
|
@ -228,6 +230,7 @@ MAKE_CTOR(CreateNewIFrameBoxObject, nsIBoxObject, NS_NewIFrameBoxO
|
|||
MAKE_CTOR(CreateNewScrollBoxObject, nsIBoxObject, NS_NewScrollBoxObject)
|
||||
MAKE_CTOR(CreateNewTreeBoxObject, nsIBoxObject, NS_NewTreeBoxObject)
|
||||
MAKE_CTOR(CreateNewAutoCopyService, nsIAutoCopyService, NS_NewAutoCopyService)
|
||||
MAKE_CTOR(CreateSelectionImageService, nsISelectionImageService,NS_NewSelectionImageService)
|
||||
|
||||
// The list of components we register
|
||||
static const nsModuleComponentInfo gComponents[] = {
|
||||
|
@ -258,6 +261,11 @@ static const nsModuleComponentInfo gComponents[] = {
|
|||
nsnull,
|
||||
CreateNewLayoutHistoryState },
|
||||
|
||||
{ "selection image storage",
|
||||
NS_SELECTIONIMAGESERVICE_CID,
|
||||
nsnull,
|
||||
CreateSelectionImageService},
|
||||
|
||||
// XXX ick
|
||||
{ "Presentation shell",
|
||||
NS_PRESSHELL_CID,
|
||||
|
|
|
@ -90,7 +90,16 @@
|
|||
// For triple-click pref
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for tripple click pref
|
||||
#include "nsISelectionImageService.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for triple click pref
|
||||
static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
|
||||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
||||
|
||||
// Some Misc #defines
|
||||
|
@ -224,6 +233,175 @@ nsIFrameDebug::RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aI
|
|||
#endif
|
||||
// end nsIFrameDebug
|
||||
|
||||
|
||||
// frame image selection drawing service implementation
|
||||
class SelectionImageService : public nsISelectionImageService
|
||||
{
|
||||
public:
|
||||
SelectionImageService();
|
||||
virtual ~SelectionImageService();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISELECTIONIMAGESERVICE
|
||||
private:
|
||||
nsresult CreateImage(nscolor aImageColor, imgIContainer *aContainer);
|
||||
nsCOMPtr<imgIContainer> mContainer;
|
||||
nsCOMPtr<imgIContainer> mDisabledContainer;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(SelectionImageService, nsISelectionImageService)
|
||||
|
||||
SelectionImageService::SelectionImageService()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
SelectionImageService::~SelectionImageService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SelectionImageService::GetImage(PRInt16 aSelectionValue, imgIContainer **aContainer)
|
||||
{
|
||||
nsresult result;
|
||||
if (aSelectionValue != nsISelectionController::SELECTION_ON)
|
||||
{
|
||||
if (!mDisabledContainer)
|
||||
{
|
||||
mDisabledContainer = do_CreateInstance("@mozilla.org/image/container;1",&result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (mDisabledContainer)
|
||||
{
|
||||
nscolor disabledTextColor = NS_RGB(255, 255, 255);
|
||||
nsCOMPtr<nsILookAndFeel> look;
|
||||
look = do_GetService(kLookAndFeelCID,&result);
|
||||
if (NS_SUCCEEDED(result) && look)
|
||||
look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, disabledTextColor);
|
||||
CreateImage(disabledTextColor, mDisabledContainer);
|
||||
}
|
||||
}
|
||||
*aContainer = mDisabledContainer;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mContainer)
|
||||
{
|
||||
mContainer = do_CreateInstance("@mozilla.org/image/container;1",&result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (mContainer)
|
||||
{
|
||||
nscolor selectionTextColor = NS_RGB(255, 255, 255);
|
||||
nsCOMPtr<nsILookAndFeel> look;
|
||||
look = do_GetService(kLookAndFeelCID,&result);
|
||||
if (NS_SUCCEEDED(result) && look)
|
||||
look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, selectionTextColor);
|
||||
CreateImage(selectionTextColor, mContainer);
|
||||
}
|
||||
}
|
||||
*aContainer = mContainer;
|
||||
}
|
||||
if (!*aContainer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aContainer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SelectionImageService::Reset()
|
||||
{
|
||||
mContainer = 0;
|
||||
mDisabledContainer = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//macintosh uses XRGB in its image format. its triple color (RGB) therefore is 4 bytes not 3
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
#define SEL_TRIPLESIZE 4
|
||||
#else
|
||||
#define SEL_TRIPLESIZE 3
|
||||
#endif
|
||||
|
||||
#define SEL_IMAGE_WIDTH 32
|
||||
#define SEL_IMAGE_HEIGHT 32
|
||||
#define SEL_WIDTH_BYTES SEL_IMAGE_WIDTH * SEL_TRIPLESIZE
|
||||
#define SEL_ALPHA_AMOUNT 128
|
||||
#define SEL_IMAGE_ALPHA_SIZE SEL_IMAGE_WIDTH*SEL_IMAGE_HEIGHT
|
||||
#define SEL_IMAGE_TOTAL_SIZE SEL_WIDTH_BYTES * SEL_IMAGE_HEIGHT
|
||||
|
||||
nsresult
|
||||
SelectionImageService::CreateImage(nscolor aImageColor, imgIContainer *aContainer)
|
||||
{
|
||||
if (aContainer)
|
||||
{
|
||||
nsresult result = aContainer->Init(SEL_IMAGE_WIDTH,SEL_IMAGE_HEIGHT,nsnull);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<gfxIImageFrame> image = do_CreateInstance("@mozilla.org/gfx/image/frame;2",&result);
|
||||
if (NS_SUCCEEDED(result) && image)
|
||||
{
|
||||
image->Init(0, 0, SEL_IMAGE_WIDTH, SEL_IMAGE_HEIGHT, gfxIFormats::RGB_A8);
|
||||
aContainer->AppendFrame(image);
|
||||
//its better to temporarily go after heap than put big data on stack
|
||||
unsigned char *data = (unsigned char *)malloc(SEL_IMAGE_TOTAL_SIZE);
|
||||
if (!data)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
unsigned char *alpha = (unsigned char *)malloc(SEL_IMAGE_ALPHA_SIZE);
|
||||
if (!alpha)
|
||||
{
|
||||
free(data);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
PRInt16 i;
|
||||
for (i = 0; i < SEL_WIDTH_BYTES; i+=SEL_TRIPLESIZE)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
data[i] = NS_GET_B(aImageColor);
|
||||
data[i+1] = NS_GET_G(aImageColor);
|
||||
data[i+2] = NS_GET_R(aImageColor);
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
data[i] = NS_GET_R(aImageColor);
|
||||
data[i+1] = NS_GET_G(aImageColor);
|
||||
data[i+2] = NS_GET_B(aImageColor);
|
||||
#endif
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
data[i] = 0
|
||||
data[i+1] = NS_GET_R(aImageColor);
|
||||
data[i+2] = NS_GET_G(aImageColor);
|
||||
data[i+3] = NS_GET_B(aImageColor);
|
||||
#endif
|
||||
}
|
||||
unsigned char *data_cur = data+SEL_WIDTH_BYTES;
|
||||
for (i = 1; i < SEL_IMAGE_HEIGHT; ++i, data_cur+=SEL_WIDTH_BYTES)
|
||||
{
|
||||
memcpy((void *)data_cur,(void *)data,SEL_WIDTH_BYTES);
|
||||
}
|
||||
memset((void *)alpha,SEL_ALPHA_AMOUNT,SEL_IMAGE_ALPHA_SIZE);
|
||||
image->SetImageData(data,SEL_IMAGE_TOTAL_SIZE, SEL_IMAGE_TOTAL_SIZE-SEL_WIDTH_BYTES);
|
||||
image->SetAlphaData(alpha,SEL_IMAGE_ALPHA_SIZE,SEL_IMAGE_ALPHA_SIZE-SEL_IMAGE_WIDTH);
|
||||
free(data);
|
||||
free(alpha);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult)
|
||||
{
|
||||
*aResult = new SelectionImageService;
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//end selection service
|
||||
|
||||
// a handy utility to set font
|
||||
void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC)
|
||||
{
|
||||
|
@ -661,6 +839,10 @@ void ForceDrawFrame(nsIPresContext* aPresContext, nsFrame * aFrame)//, PRBool)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrame::Paint(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
|
@ -742,9 +924,22 @@ nsFrame::Paint(nsIPresContext* aPresContext,
|
|||
rect.height-=2;
|
||||
rect.x=1; //we are in the coordinate system of the frame now with regards to the rendering context.
|
||||
rect.y=1;
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
||||
nsRect drawrect(rect.x, rect.y, rect.width, rect.height);
|
||||
aRenderingContext.DrawRect(drawrect);
|
||||
|
||||
nsCOMPtr<nsISelectionImageService> imageService;
|
||||
imageService = do_GetService(kSelectionImageService, &result);
|
||||
if (NS_SUCCEEDED(result) && imageService)
|
||||
{
|
||||
nsCOMPtr<imgIContainer> container;
|
||||
imageService->GetImage(selectionValue, getter_AddRefs(container));
|
||||
if (container)
|
||||
{
|
||||
nsRect rect(0, 0, mRect.width, mRect.height);
|
||||
aRenderingContext.DrawTile(container,0,0, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
SelectionDetails *deletingDetails = details;
|
||||
while ((deletingDetails = details->mNext) != nsnull) {
|
||||
delete details;
|
||||
|
@ -2872,11 +3067,6 @@ nsFrame::SetSelected(nsIPresContext* aPresContext, nsIDOMRange *aRange, PRBool a
|
|||
*/
|
||||
nsFrameState frameState;
|
||||
GetFrameState(&frameState);
|
||||
PRBool isSelected = ((frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT);
|
||||
if (aSelected == isSelected) //allready set thanks
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
if ( aSelected ){
|
||||
frameState |= NS_FRAME_SELECTED_CONTENT;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,16 @@
|
|||
// For triple-click pref
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for tripple click pref
|
||||
#include "nsISelectionImageService.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for triple click pref
|
||||
static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
|
||||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
||||
|
||||
// Some Misc #defines
|
||||
|
@ -224,6 +233,175 @@ nsIFrameDebug::RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aI
|
|||
#endif
|
||||
// end nsIFrameDebug
|
||||
|
||||
|
||||
// frame image selection drawing service implementation
|
||||
class SelectionImageService : public nsISelectionImageService
|
||||
{
|
||||
public:
|
||||
SelectionImageService();
|
||||
virtual ~SelectionImageService();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISELECTIONIMAGESERVICE
|
||||
private:
|
||||
nsresult CreateImage(nscolor aImageColor, imgIContainer *aContainer);
|
||||
nsCOMPtr<imgIContainer> mContainer;
|
||||
nsCOMPtr<imgIContainer> mDisabledContainer;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(SelectionImageService, nsISelectionImageService)
|
||||
|
||||
SelectionImageService::SelectionImageService()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
SelectionImageService::~SelectionImageService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SelectionImageService::GetImage(PRInt16 aSelectionValue, imgIContainer **aContainer)
|
||||
{
|
||||
nsresult result;
|
||||
if (aSelectionValue != nsISelectionController::SELECTION_ON)
|
||||
{
|
||||
if (!mDisabledContainer)
|
||||
{
|
||||
mDisabledContainer = do_CreateInstance("@mozilla.org/image/container;1",&result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (mDisabledContainer)
|
||||
{
|
||||
nscolor disabledTextColor = NS_RGB(255, 255, 255);
|
||||
nsCOMPtr<nsILookAndFeel> look;
|
||||
look = do_GetService(kLookAndFeelCID,&result);
|
||||
if (NS_SUCCEEDED(result) && look)
|
||||
look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, disabledTextColor);
|
||||
CreateImage(disabledTextColor, mDisabledContainer);
|
||||
}
|
||||
}
|
||||
*aContainer = mDisabledContainer;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mContainer)
|
||||
{
|
||||
mContainer = do_CreateInstance("@mozilla.org/image/container;1",&result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (mContainer)
|
||||
{
|
||||
nscolor selectionTextColor = NS_RGB(255, 255, 255);
|
||||
nsCOMPtr<nsILookAndFeel> look;
|
||||
look = do_GetService(kLookAndFeelCID,&result);
|
||||
if (NS_SUCCEEDED(result) && look)
|
||||
look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, selectionTextColor);
|
||||
CreateImage(selectionTextColor, mContainer);
|
||||
}
|
||||
}
|
||||
*aContainer = mContainer;
|
||||
}
|
||||
if (!*aContainer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aContainer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SelectionImageService::Reset()
|
||||
{
|
||||
mContainer = 0;
|
||||
mDisabledContainer = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//macintosh uses XRGB in its image format. its triple color (RGB) therefore is 4 bytes not 3
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
#define SEL_TRIPLESIZE 4
|
||||
#else
|
||||
#define SEL_TRIPLESIZE 3
|
||||
#endif
|
||||
|
||||
#define SEL_IMAGE_WIDTH 32
|
||||
#define SEL_IMAGE_HEIGHT 32
|
||||
#define SEL_WIDTH_BYTES SEL_IMAGE_WIDTH * SEL_TRIPLESIZE
|
||||
#define SEL_ALPHA_AMOUNT 128
|
||||
#define SEL_IMAGE_ALPHA_SIZE SEL_IMAGE_WIDTH*SEL_IMAGE_HEIGHT
|
||||
#define SEL_IMAGE_TOTAL_SIZE SEL_WIDTH_BYTES * SEL_IMAGE_HEIGHT
|
||||
|
||||
nsresult
|
||||
SelectionImageService::CreateImage(nscolor aImageColor, imgIContainer *aContainer)
|
||||
{
|
||||
if (aContainer)
|
||||
{
|
||||
nsresult result = aContainer->Init(SEL_IMAGE_WIDTH,SEL_IMAGE_HEIGHT,nsnull);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsCOMPtr<gfxIImageFrame> image = do_CreateInstance("@mozilla.org/gfx/image/frame;2",&result);
|
||||
if (NS_SUCCEEDED(result) && image)
|
||||
{
|
||||
image->Init(0, 0, SEL_IMAGE_WIDTH, SEL_IMAGE_HEIGHT, gfxIFormats::RGB_A8);
|
||||
aContainer->AppendFrame(image);
|
||||
//its better to temporarily go after heap than put big data on stack
|
||||
unsigned char *data = (unsigned char *)malloc(SEL_IMAGE_TOTAL_SIZE);
|
||||
if (!data)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
unsigned char *alpha = (unsigned char *)malloc(SEL_IMAGE_ALPHA_SIZE);
|
||||
if (!alpha)
|
||||
{
|
||||
free(data);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
PRInt16 i;
|
||||
for (i = 0; i < SEL_WIDTH_BYTES; i+=SEL_TRIPLESIZE)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
data[i] = NS_GET_B(aImageColor);
|
||||
data[i+1] = NS_GET_G(aImageColor);
|
||||
data[i+2] = NS_GET_R(aImageColor);
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
data[i] = NS_GET_R(aImageColor);
|
||||
data[i+1] = NS_GET_G(aImageColor);
|
||||
data[i+2] = NS_GET_B(aImageColor);
|
||||
#endif
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
data[i] = 0
|
||||
data[i+1] = NS_GET_R(aImageColor);
|
||||
data[i+2] = NS_GET_G(aImageColor);
|
||||
data[i+3] = NS_GET_B(aImageColor);
|
||||
#endif
|
||||
}
|
||||
unsigned char *data_cur = data+SEL_WIDTH_BYTES;
|
||||
for (i = 1; i < SEL_IMAGE_HEIGHT; ++i, data_cur+=SEL_WIDTH_BYTES)
|
||||
{
|
||||
memcpy((void *)data_cur,(void *)data,SEL_WIDTH_BYTES);
|
||||
}
|
||||
memset((void *)alpha,SEL_ALPHA_AMOUNT,SEL_IMAGE_ALPHA_SIZE);
|
||||
image->SetImageData(data,SEL_IMAGE_TOTAL_SIZE, SEL_IMAGE_TOTAL_SIZE-SEL_WIDTH_BYTES);
|
||||
image->SetAlphaData(alpha,SEL_IMAGE_ALPHA_SIZE,SEL_IMAGE_ALPHA_SIZE-SEL_IMAGE_WIDTH);
|
||||
free(data);
|
||||
free(alpha);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult)
|
||||
{
|
||||
*aResult = new SelectionImageService;
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//end selection service
|
||||
|
||||
// a handy utility to set font
|
||||
void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC)
|
||||
{
|
||||
|
@ -661,6 +839,10 @@ void ForceDrawFrame(nsIPresContext* aPresContext, nsFrame * aFrame)//, PRBool)
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrame::Paint(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
|
@ -742,9 +924,22 @@ nsFrame::Paint(nsIPresContext* aPresContext,
|
|||
rect.height-=2;
|
||||
rect.x=1; //we are in the coordinate system of the frame now with regards to the rendering context.
|
||||
rect.y=1;
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
||||
nsRect drawrect(rect.x, rect.y, rect.width, rect.height);
|
||||
aRenderingContext.DrawRect(drawrect);
|
||||
|
||||
nsCOMPtr<nsISelectionImageService> imageService;
|
||||
imageService = do_GetService(kSelectionImageService, &result);
|
||||
if (NS_SUCCEEDED(result) && imageService)
|
||||
{
|
||||
nsCOMPtr<imgIContainer> container;
|
||||
imageService->GetImage(selectionValue, getter_AddRefs(container));
|
||||
if (container)
|
||||
{
|
||||
nsRect rect(0, 0, mRect.width, mRect.height);
|
||||
aRenderingContext.DrawTile(container,0,0, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
SelectionDetails *deletingDetails = details;
|
||||
while ((deletingDetails = details->mNext) != nsnull) {
|
||||
delete details;
|
||||
|
@ -2872,11 +3067,6 @@ nsFrame::SetSelected(nsIPresContext* aPresContext, nsIDOMRange *aRange, PRBool a
|
|||
*/
|
||||
nsFrameState frameState;
|
||||
GetFrameState(&frameState);
|
||||
PRBool isSelected = ((frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT);
|
||||
if (aSelected == isSelected) //allready set thanks
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
if ( aSelected ){
|
||||
frameState |= NS_FRAME_SELECTED_CONTENT;
|
||||
}
|
||||
|
|
|
@ -1566,7 +1566,7 @@ PresShell::PresShell():
|
|||
if (! gLog)
|
||||
gLog = PR_NewLogModule("PresShell");
|
||||
#endif
|
||||
mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT;
|
||||
mSelectionFlags = nsISelectionDisplay::DISPLAY_TEXT | nsISelectionDisplay::DISPLAY_IMAGES;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(PresShell)
|
||||
|
|
Загрузка…
Ссылка в новой задаче