diff options
Diffstat (limited to 'ui/base')
-rwxr-xr-x | ui/base/message_box_win.cc | 41 | ||||
-rwxr-xr-x | ui/base/message_box_win.h | 26 | ||||
-rw-r--r-- | ui/base/x/x11_util.cc | 48 | ||||
-rw-r--r-- | ui/base/x/x11_util.h | 6 |
4 files changed, 67 insertions, 54 deletions
diff --git a/ui/base/message_box_win.cc b/ui/base/message_box_win.cc new file mode 100755 index 0000000..622a9d8 --- /dev/null +++ b/ui/base/message_box_win.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/message_box_win.h" + +#include <windows.h> + +#include "base/base_switches.h" +#include "base/command_line.h" +#include "base/i18n/rtl.h" +#include "base/string16.h" + +namespace ui { + +// In addition to passing the RTL flags to ::MessageBox if we are running in an +// RTL locale, we need to make sure that LTR strings are rendered correctly by +// adding the appropriate Unicode directionality marks. +int MessageBox(HWND hwnd, + const string16& text, + const string16& caption, + UINT flags) { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoMessageBox)) + return IDOK; + + UINT actual_flags = flags; + if (base::i18n::IsRTL()) + actual_flags |= MB_RIGHT | MB_RTLREADING; + + string16 localized_text = text; + base::i18n::AdjustStringForLocaleDirection(&localized_text); + const wchar_t* text_ptr = localized_text.c_str(); + + string16 localized_caption = caption; + base::i18n::AdjustStringForLocaleDirection(&localized_caption); + const wchar_t* caption_ptr = localized_caption.c_str(); + + return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags); +} + +} // namespace ui diff --git a/ui/base/message_box_win.h b/ui/base/message_box_win.h new file mode 100755 index 0000000..f9011e6 --- /dev/null +++ b/ui/base/message_box_win.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_MESSAGE_BOX_WIN_H_ +#define UI_BASE_MESSAGE_BOX_WIN_H_ +#pragma once + +#include <windows.h> + +#include "base/string16.h" + +namespace ui { + +// A wrapper around Windows' MessageBox function. Using a Chrome specific +// MessageBox function allows us to control certain RTL locale flags so that +// callers don't have to worry about adding these flags when running in a +// right-to-left locale. +int MessageBox(HWND hwnd, + const string16& text, + const string16& caption, + UINT flags); + +} // namespace ui + +#endif // UI_BASE_MESSAGE_BOX_WIN_H_ diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc index f7222fc..1232bc8 100644 --- a/ui/base/x/x11_util.cc +++ b/ui/base/x/x11_util.cc @@ -687,54 +687,6 @@ bool GetWindowManagerName(std::string* wm_name) { return !got_error && result; } -static cairo_status_t SnapshotCallback( - void *closure, const unsigned char *data, unsigned int length) { - std::vector<unsigned char>* png_representation = - static_cast<std::vector<unsigned char>*>(closure); - - size_t old_size = png_representation->size(); - png_representation->resize(old_size + length); - memcpy(&(*png_representation)[old_size], data, length); - return CAIRO_STATUS_SUCCESS; -} - -void GrabWindowSnapshot(GtkWindow* gtk_window, - std::vector<unsigned char>* png_representation) { - GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window; - Display* display = GDK_WINDOW_XDISPLAY(gdk_window); - XID win = GDK_WINDOW_XID(gdk_window); - XWindowAttributes attr; - if (XGetWindowAttributes(display, win, &attr) == 0) { - LOG(ERROR) << "Couldn't get window attributes"; - return; - } - XImage* image = XGetImage( - display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); - if (!image) { - LOG(ERROR) << "Couldn't get image"; - return; - } - if (image->depth != 24) { - LOG(ERROR)<< "Unsupported image depth " << image->depth; - return; - } - cairo_surface_t* surface = - cairo_image_surface_create_for_data( - reinterpret_cast<unsigned char*>(image->data), - CAIRO_FORMAT_RGB24, - image->width, - image->height, - image->bytes_per_line); - - if (!surface) { - LOG(ERROR) << "Unable to create Cairo surface from XImage data"; - return; - } - cairo_surface_write_to_png_stream( - surface, SnapshotCallback, png_representation); - cairo_surface_destroy(surface); -} - bool ChangeWindowDesktop(XID window, XID destination) { int desktop; if (!GetWindowDesktop(destination, &desktop)) diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h index 3284fcb..e323d8b 100644 --- a/ui/base/x/x11_util.h +++ b/ui/base/x/x11_util.h @@ -20,7 +20,6 @@ typedef unsigned long Atom; typedef struct _GdkDrawable GdkWindow; typedef struct _GtkWidget GtkWidget; -typedef struct _GtkWindow GtkWindow; typedef unsigned long XID; typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers. typedef struct _XDisplay Display; @@ -171,11 +170,6 @@ bool GetWindowParent(XID* parent_window, bool* parent_is_root, XID window); // Get the window manager name. bool GetWindowManagerName(std::string* name); -// Grabs a snapshot of the designated window and stores a PNG representation -// into a byte vector. -void GrabWindowSnapshot(GtkWindow* gdk_window, - std::vector<unsigned char>* png_representation); - // Change desktop for |window| to the desktop of |destination| window. bool ChangeWindowDesktop(XID window, XID destination); |