* Integrated the Go button into the URL text field.

* Added a context menu to the URL input for integration with the system
  clipboard when you want to use the mouse only.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@403 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi 2010-04-08 15:52:28 +00:00 committed by Alexandre Deckner
parent 312655fb6f
commit ad7c99c0ca
5 changed files with 273 additions and 17 deletions

View File

@ -243,11 +243,8 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
fStopButton->SetIcon(204);
fStopButton->TrimIcon();
// URL
fURLInputGroup = new URLInputGroup();
// Go
fGoButton = new BButton("", "Go", new BMessage(GOTO_URL));
// URL input group
fURLInputGroup = new URLInputGroup(new BMessage(GOTO_URL));
// Status Bar
fStatusText = new BStringView("status", "");
@ -291,7 +288,6 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
.Add(fForwardButton, 1, 0)
.Add(fStopButton, 2, 0)
.Add(fURLInputGroup, 3, 0)
.Add(fGoButton, 4, 0)
.SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing)
)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
@ -381,11 +377,11 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)
// the text control just goes out of focus.
if (bytes[0] == B_RETURN) {
// Do it in such a way that the user sees the Go-button go down.
fGoButton->SetValue(B_CONTROL_ON);
fURLInputGroup->GoButton()->SetValue(B_CONTROL_ON);
UpdateIfNeeded();
fGoButton->Invoke();
fURLInputGroup->GoButton()->Invoke();
snooze(1000);
fGoButton->SetValue(B_CONTROL_OFF);
fURLInputGroup->GoButton()->SetValue(B_CONTROL_OFF);
}
} else if (bytes[0] == B_LEFT_ARROW && (modifiers & B_COMMAND_KEY) != 0) {
PostMessage(GO_BACK);

View File

@ -149,7 +149,6 @@ private:
IconButton* fBackButton;
IconButton* fForwardButton;
IconButton* fStopButton;
BButton* fGoButton;
URLInputGroup* fURLInputGroup;
BStringView* fStatusText;
BStatusBar* fLoadingProgressBar;

View File

@ -5,13 +5,18 @@
#include "URLInputGroup.h"
#include <Bitmap.h>
#include <Button.h>
#include <ControlLook.h>
#include <Clipboard.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutUtils.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <SeparatorView.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <stdio.h>
@ -127,10 +132,14 @@ static const float kHorizontalTextRectInset = 3.0;
class URLInputGroup::URLTextView : public BTextView {
private:
static const uint32 MSG_CLEAR = 'cler';
public:
URLTextView(URLInputGroup* parent);
virtual ~URLTextView();
virtual void MessageReceived(BMessage* message);
virtual void FrameResized(float width, float height);
virtual void MouseDown(BPoint where);
virtual void KeyDown(const char* bytes, int32 numBytes);
@ -171,6 +180,20 @@ URLInputGroup::URLTextView::~URLTextView()
}
void
URLInputGroup::URLTextView::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_CLEAR:
SetText("");
break;
default:
BTextView::MessageReceived(message);
break;
}
}
void
URLInputGroup::URLTextView::FrameResized(float width, float height)
{
@ -182,12 +205,52 @@ URLInputGroup::URLTextView::FrameResized(float width, float height)
void
URLInputGroup::URLTextView::MouseDown(BPoint where)
{
if (!IsFocus()) {
bool wasFocus = IsFocus();
if (!wasFocus)
MakeFocus(true);
int32 buttons;
if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK)
buttons = B_PRIMARY_MOUSE_BUTTON;
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) {
// Display context menu
int32 selectionStart;
int32 selectionEnd;
GetSelection(&selectionStart, &selectionEnd);
bool canCutOrCopy = selectionEnd > selectionStart;
bool canPaste = false;
if (be_clipboard->Lock()) {
if (BMessage* data = be_clipboard->Data())
canPaste = data->HasData("text/plain", B_MIME_TYPE);
be_clipboard->Unlock();
}
BMenuItem* cutItem = new BMenuItem("Cut", new BMessage(B_CUT));
BMenuItem* copyItem = new BMenuItem("Copy", new BMessage(B_COPY));
BMenuItem* pasteItem = new BMenuItem("Paste", new BMessage(B_PASTE));
BMenuItem* clearItem = new BMenuItem("Clear", new BMessage(MSG_CLEAR));
cutItem->SetEnabled(canCutOrCopy);
copyItem->SetEnabled(canCutOrCopy);
pasteItem->SetEnabled(canPaste);
clearItem->SetEnabled(strlen(Text()) > 0);
BPopUpMenu* menu = new BPopUpMenu("url context");
menu->AddItem(cutItem);
menu->AddItem(copyItem);
menu->AddItem(pasteItem);
menu->AddItem(clearItem);
menu->SetTargetForItems(this);
menu->Go(ConvertToScreen(where), true, true, true);
return;
}
// Only pass through to base class if we already have focus.
if (!wasFocus)
return;
BTextView::MouseDown(where);
}
@ -295,10 +358,145 @@ URLInputGroup::URLTextView::_AlignTextRect()
}
// #pragma mark - GoButton
const uint32 kGoBitmapWidth = 14;
const uint32 kGoBitmapHeight = 14;
const color_space kGoBitmapFormat = B_RGBA32;
const unsigned char kGoBitmapBits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xde, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x07,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x9c, 0xd5, 0xa6, 0xff,
0x4a, 0x67, 0x50, 0xff, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xb6, 0xf9, 0xc2, 0xff, 0xb2, 0xf9, 0xc0, 0xff, 0x88, 0xbb, 0x91, 0xff,
0x2e, 0x3d, 0x32, 0xff, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xb6, 0xf9, 0xc2, 0xff,
0x73, 0xfa, 0x8c, 0xff, 0x9f, 0xf9, 0xae, 0xff, 0xac, 0xed, 0xb7, 0xff, 0x63, 0x96, 0x6d, 0xff,
0x00, 0x00, 0x00, 0xe9, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xb6, 0xf9, 0xc2, 0xff, 0x5d, 0xfc, 0x7b, 0xff, 0x5d, 0xfc, 0x7b, 0xff,
0x72, 0xf9, 0x88, 0xff, 0x6d, 0xe5, 0x82, 0xff, 0x50, 0xbf, 0x65, 0xff, 0x27, 0x63, 0x32, 0xff,
0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xb4, 0xf8, 0xc0, 0xff,
0x59, 0xfc, 0x77, 0xff, 0x59, 0xfc, 0x77, 0xff, 0x59, 0xfc, 0x77, 0xff, 0x59, 0xfb, 0x76, 0xff,
0x4a, 0xe8, 0x67, 0xff, 0x32, 0xcc, 0x50, 0xff, 0x27, 0x9e, 0x3d, 0xff, 0x15, 0x3d, 0x15, 0xff,
0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xa2, 0xf2, 0xb0, 0xff, 0x2e, 0xfa, 0x54, 0xff, 0x2e, 0xfa, 0x54, 0xff,
0x2e, 0xfa, 0x54, 0xff, 0x2e, 0xf9, 0x54, 0xff, 0x27, 0xe4, 0x48, 0xff, 0x15, 0xc5, 0x38, 0xff,
0x15, 0x98, 0x2e, 0xff, 0x00, 0x3b, 0x15, 0xff, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x26,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x88, 0xe9, 0x99, 0xff,
0x15, 0xf9, 0x40, 0xff, 0x15, 0xf9, 0x40, 0xff, 0x15, 0xed, 0x3d, 0xff, 0x00, 0xc8, 0x2b, 0xff,
0x00, 0xa5, 0x22, 0xff, 0x00, 0x57, 0x15, 0xff, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x63,
0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x72, 0xe0, 0x86, 0xff, 0x22, 0xf5, 0x42, 0xff, 0x27, 0xda, 0x46, 0xff,
0x15, 0xb6, 0x32, 0xff, 0x00, 0x74, 0x1c, 0xff, 0x00, 0x00, 0x00, 0xe9, 0x00, 0x00, 0x00, 0x81,
0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x5f, 0xda, 0x76, 0xff,
0x42, 0xd2, 0x5a, 0xff, 0x22, 0x95, 0x35, 0xff, 0x00, 0x2e, 0x00, 0xff, 0x00, 0x00, 0x00, 0xa2,
0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x46, 0xb6, 0x5c, 0xff, 0x1c, 0x54, 0x22, 0xff, 0x00, 0x00, 0x00, 0xc4,
0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x00, 0xde,
0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
class BitmapButton : public BButton {
static const float kFrameInset = 2;
public:
BitmapButton(const char* resourceName, BMessage* message)
:
BButton("", message),
fBitmap(BTranslationUtils::GetBitmap(resourceName))
{
}
BitmapButton(const uint8* bits, uint32 width, uint32 height,
color_space format, BMessage* message)
:
BButton("", message),
fBitmap(new BBitmap(BRect(0, 0, width - 1, height - 1), 0, format))
{
memcpy(fBitmap->Bits(), bits, fBitmap->BitsLength());
}
~BitmapButton()
{
delete fBitmap;
}
virtual BSize MinSize()
{
BSize min(0, 0);
if (fBitmap) {
min.width = fBitmap->Bounds().Width();
min.height = fBitmap->Bounds().Height();
}
min.width += kFrameInset * 2;
min.height += kFrameInset * 2;
return min;
}
virtual BSize MaxSize()
{
return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
}
virtual BSize PreferredSize()
{
return MinSize();
}
virtual void Draw(BRect updateRect)
{
BRect bounds(Bounds());
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = be_control_look->Flags(this);
be_control_look->DrawButtonBackground(this, bounds, updateRect, base,
flags);
SetDrawingMode(B_OP_ALPHA);
if (!IsEnabled()) {
SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
SetHighColor(0, 0, 0, 120);
}
BPoint bitmapLocation(kFrameInset, kFrameInset);
if (Value() == B_CONTROL_ON)
bitmapLocation += BPoint(1, 1);
DrawBitmap(fBitmap, bitmapLocation);
}
private:
BBitmap* fBitmap;
};
// #pragma mark - URLInputGroup
URLInputGroup::URLInputGroup()
URLInputGroup::URLInputGroup(BMessage* goMessage)
:
BGroupView(B_HORIZONTAL),
fWindowActive(false)
@ -308,6 +506,15 @@ URLInputGroup::URLInputGroup()
fTextView = new URLTextView(this);
AddChild(fTextView);
AddChild(new BSeparatorView(B_VERTICAL, B_PLAIN_BORDER));
// TODO: Fix in Haiku, no in-built support for archived BBitmaps from
// resources?
// fGoButton = new BitmapButton("kActionGo", NULL);
fGoButton = new BitmapButton(kGoBitmapBits, kGoBitmapWidth,
kGoBitmapHeight, kGoBitmapFormat, goMessage);
GroupLayout()->AddView(fGoButton, 0.0);
SetFlags(Flags() | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
SetLowColor(ViewColor());
SetViewColor(B_TRANSPARENT_COLOR);
@ -382,3 +589,11 @@ URLInputGroup::Text() const
return fTextView->Text();
}
BButton*
URLInputGroup::GoButton() const
{
return fGoButton;
}

View File

@ -7,12 +7,13 @@
#include <GroupView.h>
class BButton;
class BTextView;
class URLInputGroup : public BGroupView {
public:
URLInputGroup();
URLInputGroup(BMessage* goMessage);
virtual ~URLInputGroup();
virtual void AttachedToWindow();
@ -24,10 +25,13 @@ public:
void SetText(const char* text);
const char* Text() const;
BButton* GoButton() const;
private:
class URLTextView;
URLTextView* fTextView;
BButton* fGoButton;
bool fWindowActive;
};

View File

@ -252,7 +252,7 @@ resource vector_icon {
$"44013402360000000000000000360000485000466000"
};
resource(201) #'VICN' array {
resource(201, "kActionBack") #'VICN' array {
$"6E636966070500020006023B2FA63AC896BCCBD33D335A4A6980490D0B00ACE2"
$"FFFF6ECDFF0200060236D841374D6EBD38553CC6154AA9DF4607770026A8EBFF"
$"0694DE020006023729EA388C8FBC29073AAE614A51AF4A729A00035E8CFF0585"
@ -265,7 +265,7 @@ resource(201) #'VICN' array {
$"05000A06020607100117812004"
};
resource(202) #'VICN' array {
resource(202, "kActionForward") #'VICN' array {
$"6E636966050500020006023B2FA63AC896BCCBD33D335A4A6980490D0B00ACE2"
$"FFFF6ECDFF0200060239AF2C39E19BBC89D83C68DC4AFA1247CFA20006A5F7FF"
$"069EEC02000602B8EEBEB986C33C7FB4BC13FB46FA0C49FBDD000592DAFD3EBD"
@ -275,7 +275,7 @@ resource(202) #'VICN' array {
$"0A020102000A030103000A040104100117812004"
};
resource(203) #'VICN' array {
resource(203, "kActionForward2") #'VICN' array {
$"6E63696607050002000602396DF23A056B3B94FCBB09F547CD484AAB5F0090D9"
$"FFFF6ECDFF02000602B5E5793878A83E023B3B2AC34893F147CC490060C8FFFF"
$"44BEFD02000602B6F90538542D3C2FCA3ACA9249A8634A929A00034F77FF0468"
@ -288,7 +288,7 @@ resource(203) #'VICN' array {
$"000A06020607100117812004"
};
resource(204) #'VICN' array {
resource(204, "kActionStop") #'VICN' array {
$"6E63696606050102000602393D323BB602BEA28F3C4CC64B601449439F00FF3E"
$"3EFFF70606020006033B27153C10C7BDF9893D088A4B2F634882C500C805057D"
$"9D0404FFB4040403750303020006023B06EB3B5469BC08EB3BB31F4AB15D4478"
@ -301,3 +301,45 @@ resource(204) #'VICN' array {
$"000A0503070809100117810004"
};
resource(205, "kActionGo") archive BBitmap {
"_frame" = rect { 0.0, 0.0, 15.0, 15.0 },
"_cspace" = 8200,
"_bmflags" = 0,
"_rowbytes" = 64,
"_data" = array {
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000C1000000DE00000061000000070000000100000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000FF9BD4A5FF48634EFF000000C00000003500000004"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000FFB6F9C2FFB3F9C0FF84B68EFF263426FD0000009B"
$"0000001600000002000000000000000000000000000000000000000000000000"
$"0000000000000000000000FFB6F9C2FF7EF995FFA3F9B3FFAAE9B6FF69906FFF"
$"000000E200000064000000070000000100000000000000000000000000000000"
$"0000000000000000000000FFB6F9C2FF6AFB85FF6AFB85FF83FA98FFA4F5B2FF"
$"7CC88AFF325C3BFF000000C00000003500000004000000000000000000000000"
$"0000000000000000000000FFB6F9C2FF5DFC7BFF5DFC7BFF5DFC7BFF5DFB7CFF"
$"60ED7AFF54D76DFF389A48FF002A14FD0000009B000000160000000200000000"
$"0000000000000000000000FFB5F8C1FF59FC77FF59FC77FF59FC77FF59FC77FF"
$"59FC77FF55F674FF40DB5CFF2BBC48FF1C752BFF000000D00000002000000003"
$"0000000000000000000000FFA8F4B5FF2EFA54FF2EFA54FF2EFA54FF2EFA54FF"
$"2EFA54FF2BF350FF22D542FF1CB638FF157027FF000000D00000003D00000009"
$"0000000000000000000000FF92ECA2FF15F940FF15F940FF15F940FF15F740FF"
$"15DE35FF00BE2EFF008922FF002600FD0000009B000000430000002000000003"
$"0000000000000000000000FF7EE591FF15F83DFF15F83DFF1CEA3DFF00C732FF"
$"009E22FF004815FF000000BF000000560000002D0000000F0000000200000000"
$"0000000000000000000000FF6DDF81FF1CF340FF2BDA4AFF1CB638FF006D1CFF"
$"000000E200000074000000360000001900000004000000000000000000000000"
$"0000000000000000000000FF5DDA75FF44D25FFF229338FF002600FD0000009B"
$"0000004300000023000000070000000100000000000000000000000000000000"
$"0000000000000000000000FF46B65CFF1C5222FF000000BF000000560000002D"
$"0000000F00000002000000000000000000000000000000000000000000000000"
$"0000000000000000000000C2000000DE00000074000000360000001900000004"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000030000001F00000020000000080000000100000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
}
};