~maxolasersquad/ubuntu/precise/epiphany-browser/add_quicklist

« back to all changes in this revision

Viewing changes to src/ephy-find-toolbar.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2010-10-14 12:45:29 UTC
  • mfrom: (98.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20101014124529-57hi6lecoo68e3sq
Tags: 2.30.6-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Update the search URL:
    + add debian/patches/80_ubuntu_search_url.patch
    + update debian/epiphany-browser-data.gconf-defaults
  - Set branding to Ubuntu.
  - debian/patches/81_ubuntu_force_update_bookmarks_menu.patch:
    + Update the bookmarks menu every time the internal structure
      is changed (needed for the UNE application menu to work correctly).
  - Support appindicator.
  - debian/control.in:
    + Temporary bump for gir dependencies to ensure we rebuild against
      the correct version.
  - debian/patches/13_clearing_temp.patch:
    + Fix crashing epiphany-browser while clearing temp files.
      This patch can be dropped with new upstream 2.32 release.
* debian/control.in:
  - Bump Build-Depends on network-manager-dev to avoid FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
typedef enum
75
75
{
76
 
        EPHY_FIND_FOUND         = 0,
77
 
        EPHY_FIND_NOTFOUND      = 1,
78
 
        EPHY_FIND_FOUNDWRAPPED  = 2
79
 
} EphyEmbedFindResult;
 
76
        EPHY_FIND_RESULT_FOUND          = 0,
 
77
        EPHY_FIND_RESULT_NOTFOUND       = 1,
 
78
        EPHY_FIND_RESULT_FOUNDWRAPPED   = 2
 
79
} EphyFindResult;
 
80
 
 
81
typedef enum
 
82
{
 
83
        EPHY_FIND_DIRECTION_NEXT,
 
84
        EPHY_FIND_DIRECTION_PREV
 
85
} EphyFindDirection;
80
86
 
81
87
static guint signals[LAST_SIGNAL];
82
88
 
131
137
 
132
138
static void
133
139
set_status (EphyFindToolbar *toolbar,
134
 
            EphyEmbedFindResult result)
 
140
            EphyFindResult result)
135
141
{
136
142
        EphyFindToolbarPrivate *priv = toolbar->priv;
137
143
        char *text = NULL;
139
145
 
140
146
        switch (result)
141
147
        {
142
 
                case EPHY_FIND_FOUND:
 
148
                case EPHY_FIND_RESULT_FOUND:
143
149
                        text = NULL;
144
150
                        break;
145
 
                case EPHY_FIND_NOTFOUND:
 
151
                case EPHY_FIND_RESULT_NOTFOUND:
146
152
                        {
147
153
                                text = _("Not found");
148
154
 
155
161
                                priv->source_id = g_timeout_add (500, (GSourceFunc) set_status_notfound_cb, toolbar);
156
162
                        }
157
163
                        break;
158
 
                case EPHY_FIND_FOUNDWRAPPED:
 
164
                case EPHY_FIND_RESULT_FOUNDWRAPPED:
159
165
                        text = _("Wrapped");
160
166
                        break;
161
167
        }
239
245
        webkit_web_view_set_highlight_text_matches (web_view, TRUE);
240
246
}
241
247
 
242
 
static EphyEmbedFindResult
 
248
static EphyFindResult
243
249
real_find (EphyFindToolbarPrivate *priv,
244
 
           gboolean forward)
 
250
           EphyFindDirection direction)
245
251
{
246
252
        WebKitWebView *web_view = priv->web_view;
247
253
        gboolean case_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->case_sensitive));
 
254
        gboolean forward = (direction == EPHY_FIND_DIRECTION_NEXT);
248
255
 
249
256
        if (!priv->find_string || !g_strcmp0 (priv->find_string, ""))
250
 
                return EPHY_FIND_NOTFOUND;
 
257
                return EPHY_FIND_RESULT_NOTFOUND;
251
258
 
252
259
        if (!webkit_web_view_search_text
253
260
            (web_view, priv->find_string, case_sensitive, forward, FALSE)) {
255
262
                if (!webkit_web_view_search_text
256
263
                    (web_view, priv->find_string, case_sensitive, forward, TRUE)) {
257
264
                        /* there's no result */
258
 
                        return EPHY_FIND_NOTFOUND;
 
265
                        return EPHY_FIND_RESULT_NOTFOUND;
259
266
                } else {
260
267
                        /* found wrapped */
261
 
                        return EPHY_FIND_FOUNDWRAPPED;
 
268
                        return EPHY_FIND_RESULT_FOUNDWRAPPED;
262
269
                }
263
270
        }
264
271
 
265
 
        return EPHY_FIND_FOUND;
 
272
        return EPHY_FIND_RESULT_FOUND;
266
273
}
267
274
 
268
275
static gboolean
269
276
do_search (EphyFindToolbar *toolbar)
270
277
{
271
278
        EphyFindToolbarPrivate *priv = toolbar->priv;
272
 
        EphyEmbedFindResult result;
 
279
        EphyFindResult result;
273
280
 
274
281
        priv->find_source_id = 0;
275
282
 
276
283
        ephy_find_toolbar_mark_matches (toolbar);
277
284
 
278
 
        result = real_find (priv, TRUE);
 
285
        result = real_find (priv, EPHY_FIND_DIRECTION_NEXT);
279
286
        set_status (toolbar, result);
280
287
 
281
288
        return FALSE;
429
436
         */
430
437
        if (case_sensitive)
431
438
        {
432
 
                EphyEmbedFindResult result;
 
439
                EphyFindResult result;
433
440
 
434
 
                result = real_find (toolbar->priv, FALSE);
435
 
                if (result != EPHY_FIND_NOTFOUND)
436
 
                        result = real_find (toolbar->priv, TRUE);
 
441
                result = real_find (toolbar->priv, EPHY_FIND_DIRECTION_PREV);
 
442
                if (result != EPHY_FIND_RESULT_NOTFOUND)
 
443
                        result = real_find (toolbar->priv,
 
444
                                            EPHY_FIND_DIRECTION_NEXT);
437
445
 
438
446
                set_status (toolbar, result);
439
447
        }
778
786
typedef struct
779
787
{
780
788
        EphyFindToolbar *toolbar;
781
 
        gboolean next;
 
789
        gboolean direction;
 
790
        gboolean highlight;
782
791
} FindAgainCBStruct;
783
792
 
784
793
static void
787
796
        g_slice_free (FindAgainCBStruct, data);
788
797
}
789
798
 
790
 
static EphyEmbedFindResult
791
 
ephy_find_toolbar_find_again (EphyFindToolbar *toolbar,
792
 
                              gboolean forward,
793
 
                              gboolean links_only)
794
 
{
795
 
  EphyFindToolbarPrivate *priv = toolbar->priv;
796
 
 
797
 
  return real_find (priv, forward);
798
 
}
799
 
 
800
799
static gboolean
801
800
find_again_cb (FindAgainCBStruct *data)
802
801
{
803
 
        EphyEmbedFindResult result;
 
802
        EphyFindResult result;
804
803
        EphyFindToolbarPrivate *priv = data->toolbar->priv;
805
804
 
806
 
        result = ephy_find_toolbar_find_again (data->toolbar, data->next,
807
 
                                  priv->links_only);
 
805
        result = real_find (priv, data->direction);
 
806
 
 
807
        /* Highlight matches again if the toolbar was hidden when the user
 
808
         * requested find-again. */
 
809
        if (result != EPHY_FIND_RESULT_NOTFOUND && data->highlight)
 
810
                ephy_find_toolbar_mark_matches (data->toolbar);
 
811
 
808
812
        set_status (data->toolbar, result);
809
813
 
810
814
        priv->find_again_source_id = 0;
812
816
        return FALSE;
813
817
}
814
818
 
 
819
static void
 
820
find_again (EphyFindToolbar *toolbar, EphyFindDirection direction)
 
821
{
 
822
        GtkWidget *widget = GTK_WIDGET (toolbar);
 
823
        EphyFindToolbarPrivate *priv = toolbar->priv;
 
824
        FindAgainCBStruct *data;
 
825
        gboolean visible;
 
826
 
 
827
        visible = gtk_widget_get_visible (widget);
 
828
        if (!visible) {
 
829
                gtk_widget_show (widget);
 
830
                gtk_widget_grab_focus (widget);
 
831
        }
 
832
 
 
833
        /* We need to do this to give time to the embed to sync with the size
 
834
         * change due to the toolbar being shown, otherwise the toolbar can
 
835
         * obscure the result. See GNOME bug #415074.
 
836
         */
 
837
        if (priv->find_again_source_id != 0) return;
 
838
 
 
839
        data = g_slice_new0 (FindAgainCBStruct);
 
840
        data->toolbar = toolbar;
 
841
        data->direction = direction;
 
842
        data->highlight = !visible;
 
843
 
 
844
        priv->find_again_source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
 
845
                                                      (GSourceFunc) find_again_cb,
 
846
                                                      data,
 
847
                                                      (GDestroyNotify) find_again_data_destroy_cb);
 
848
}
 
849
 
815
850
void
816
851
ephy_find_toolbar_find_next (EphyFindToolbar *toolbar)
817
852
{
818
 
        GtkWidget *widget = GTK_WIDGET (toolbar);
819
 
        EphyFindToolbarPrivate *priv = toolbar->priv;
820
 
        FindAgainCBStruct *data;
821
 
 
822
 
        if (!gtk_widget_get_visible (widget)) {
823
 
                gtk_widget_show (widget);
824
 
                gtk_widget_grab_focus (widget);
825
 
        }
826
 
 
827
 
        /* We need to do this here (and in find_previous) to give time to the embed
828
 
         * to sync with the size change due to the toolbar being shown, otherwise
829
 
         * the toolbar can obscure the result. See GNOME bug #415074.
830
 
         */
831
 
 
832
 
        if (priv->find_again_source_id != 0) return;
833
 
 
834
 
        data = g_slice_new0 (FindAgainCBStruct);
835
 
        data->toolbar = toolbar;
836
 
        data->next = TRUE;
837
 
 
838
 
        priv->find_again_source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
839
 
                                                      (GSourceFunc) find_again_cb,
840
 
                                                      data,
841
 
                                                      (GDestroyNotify) find_again_data_destroy_cb);
 
853
        find_again (toolbar, EPHY_FIND_DIRECTION_NEXT);
842
854
}
843
855
 
844
856
void
845
857
ephy_find_toolbar_find_previous (EphyFindToolbar *toolbar)
846
858
{
847
 
        GtkWidget *widget = GTK_WIDGET (toolbar);
848
 
        EphyFindToolbarPrivate *priv = toolbar->priv;
849
 
        FindAgainCBStruct *data;
850
 
 
851
 
        if (!gtk_widget_get_visible (widget)) {
852
 
                gtk_widget_show (widget);
853
 
                gtk_widget_grab_focus (widget);
854
 
        }
855
 
 
856
 
        if (priv->find_again_source_id != 0) return;
857
 
 
858
 
        data = g_slice_new0 (FindAgainCBStruct);
859
 
        data->toolbar = toolbar;
860
 
        data->next = FALSE;
861
 
 
862
 
        priv->find_again_source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
863
 
                                                      (GSourceFunc) find_again_cb,
864
 
                                                      data,
865
 
                                                      (GDestroyNotify) find_again_data_destroy_cb);
 
859
        find_again (toolbar, EPHY_FIND_DIRECTION_PREV);
866
860
}
867
861
 
868
862
void
885
879
        gtk_widget_grab_focus (GTK_WIDGET (toolbar));
886
880
}
887
881
 
888
 
static void
889
 
ephy_find_toolbar_set_selection (EphyFindToolbar *toolbar,
890
 
                                 gboolean attention)
891
 
{
892
 
        WebKitWebView *web_view = toolbar->priv->web_view;
893
 
 
894
 
        webkit_web_view_set_highlight_text_matches (web_view, attention);
895
 
}
896
 
 
897
882
void
898
883
ephy_find_toolbar_close (EphyFindToolbar *toolbar)
899
884
{
902
887
        gtk_widget_hide (GTK_WIDGET (toolbar));
903
888
 
904
889
        if (priv->web_view == NULL) return;
905
 
        ephy_find_toolbar_set_selection (toolbar, FALSE);
 
890
 
 
891
        webkit_web_view_set_highlight_text_matches (priv->web_view, FALSE);
906
892
}
907
893
 
908
894
void